聚合列表中的Elasticsearch两级排序 [英] Elasticsearch two level sort in aggregation list
问题描述
目前,我正在按文档分数对汇总进行排序,因此,最相关的项目在汇总列表中排在首位,如下所示:
Currently I am sorting aggregations by document score, so most relevant items come first in aggregation list like below:
{
'aggs' : {
'guilds' : {
'terms' : {
'field' : 'guilds.title.original',
'order' : [{'max_score' : 'desc'}],
'aggs' : {
'max_score' : {
'script' : 'doc.score'
}
}
}
}
}
}
我想在JSON中向订单条款订单数组添加另一个排序选项.但是当我这样做的时候:
I want to add another sort option to the order terms order array in my JSON. but when I do that like this :
{
'order' : [{'max_score' : 'desc'}, {"_count" : "desc"},
}
第二种方法不起作用.例如,当所有分数均相等时,则应基于查询进行排序,但不起作用.
The second sort does not work. For example when all of the scores are equal it then should sort based on query but it does not work.
推荐答案
作为对安德烈(Andrei)的答案...的更正,以便按照多个条件对聚合进行排序,您必须创建一个数组,如
As a correction to Andrei's answer ... to order aggregations by multiple criteria, you MUST create an array as shown in Terms Aggregation: Order and you MUST be using ElasticSearch 1.5 or later.
因此,对于安德烈(Andrei)的回答,更正为:
"order" : [ { "max_score": "desc" }, { "_count": "desc" } ]
So, for Andrei's answer, the correction is:
"order" : [ { "max_score": "desc" }, { "_count": "desc" } ]
正如安德烈(Andrei)所言,ES不会抱怨,但会仅使用订单"元素中列出的最后一项.
As Andrei has it, ES will not complain but it will ONLY use the last item listed in the "order" element.
这篇关于聚合列表中的Elasticsearch两级排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!