我有两个字段:count(对象)和countyby(文本)。计数对象具有几个数字类型的嵌套属性:
"count" : {
"properties" :
"value1" : {
"type" : "long"
},
"value2" : {
"type" : "long"
},
"value3" : {
"type" : "long"
},
"value4" : {
"type" : "long"
},
"value5" : {
"type" : "long"
}
},
"countBy": {
type: "keyword"
}
我需要进行搜索,以根据countBy属性中指定的count的嵌套属性的值对文档进行排序
答案 0 :(得分:1)
您可以使用script-based sorting来实现:
"sort" : {
"_script" : {
"type" : "number",
"script" : {
"lang": "painless",
"source": "doc['countBy'].value != null ? doc['count.'+doc['countBy'].value].value : 0"
},
"order" : "desc"
}
}