【发布时间】:2017-10-04 21:46:08
【问题描述】:
我正在尝试通过一组嵌套的键值对对 ElasticSearch 5 中的搜索结果进行排序。即:
我有以下结果(伪结构,为了简单起见):
{
"hit1": {
"nested_objects": [
{
"Key": "abc",
"Value": 0.1
},
{
"Key": "def",
"Value": 0.3
}
]
},
"hit2": {
"nested_objects": [
{
"Key": "abc",
"Value": 0.9
},
{
"Key": "def",
"Value": 0.1
}
]
}
}
我希望它按“Key = 'abc' 的最高值”排序,这意味着“hit2”将排在首位。
我的映射如下:
{
"test_index": {
"mappings": {
"test_type": {
"properties": {
"nested_objects": {
"type": "nested",
"properties": {
"Key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Value": {
"type": "float"
}
}
}
}
}
}
}
}
我已尝试遵循以下建议:
Sort elastic search query based on a nested key value array
Sort nested object in Elasticsearch
...但我一直收到以下错误:
"Fielddata is disabled on text fields by default"
重现此情况的排序尝试示例:
{
"sort": [
{
"nested_objects.Key": {
"order": "desc",
"nested_path": "nested_objects",
"nested_filter": {
"term": { "nested_objects.Key": "abc" }
}
}
}
]
}
解决此问题的最佳实践方法是什么?启用字段数据(使用大量内存)真的是这里唯一的选择吗?
【问题讨论】:
标签: sorting elasticsearch