ElasticSearch - 排序不起作用
ElasticSearch - Sort does not work
我正在尝试进行搜索并对结果进行排序。但是,我收到一个错误,不知道为什么。
编辑 - 我将提供我的完整映射。
"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
我也检查了这个link:
DOCUMENTATION
有人可以帮助我吗?
嗯,这可能是您的映射设置不正确。我跟着使用以下内容:
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" } }
]
}
所以一定要检查一下:
- Naming/typo的(你永远不知道)
- 您的映射(是否有 "myfield.sort" 字段)
- 您是否在正确的索引中搜索?
希望这对您有所帮助
我正在尝试进行搜索并对结果进行排序。但是,我收到一个错误,不知道为什么。
编辑 - 我将提供我的完整映射。
"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
我也检查了这个link: DOCUMENTATION
有人可以帮助我吗?
嗯,这可能是您的映射设置不正确。我跟着使用以下内容:
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" } }
]
}
所以一定要检查一下:
- Naming/typo的(你永远不知道)
- 您的映射(是否有 "myfield.sort" 字段)
- 您是否在正确的索引中搜索?
希望这对您有所帮助