我正在尝试搜索并对结果进行排序。但是,我得到一个错误,不知道为什么。
编辑 - 我会提供完整的映射。
"myindex": {
"mappings": {
"mytype": {
"dynamic_templates": [
{
// Dynamic templates here!
}
],
"properties": {
"fieldid": {
"type": "keyword",
"store": true
},
"fields": {
"properties": {
"myfield": {
"type": "text",
"fields": {
"sort": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "myanalyzer"
}
}
},
"isDirty": {
"type": "boolean"
}
}
}
}
}
}
当我使用排序执行搜索时,如下所示:
POST /index/_search
{
"sort": [
{ "myfield.sort" : {"order" : "asc"}}
]
}
我收到以下错误:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for [myfield.sort] in order to sort on",
"index_uuid": "VxyKnppiRJCrrnXfaGAEfA",
"index": "index"
}
]
"status": 400
}
我正在关注elasticsearch的文档。 DOCUMENTATION
我也查看此链接: DOCUMENTATION
有人可以帮我吗?
答案 0 :(得分:1)
嗯,你的映射可能没有正确设置。我跟着使用了以下内容:
PUT /your-index/
{
"settings": {
"number_of_replicas": "1",
"number_of_shards": "3",
"analysis": {
"customanalyzer": {
"ID": {
"type": "custom",
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
}
},
"mappings": {
"thingy": {
"properties": {
"myfield": {
"type": "text",
"analyzer": "ID",
"fields": {
"sort": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
要仔细检查索引是否实际有myfield.sort
字段查看
GET /your-index/thingy/_mapping
然后,上传一些文件(无需指定子字段,elasticsearch将为您完成)
POST /your-index/thingy/
{
"myfield": "some-value"
}
现在我可以搜索以下内容:
POST /your-index/thingy/_search
{
"sort": [
{ "myfield.sort": { "order": "asc" } }
]
}
所以一定要检查:
希望这会有所帮助