I am trying to sort the aggregated result by applying another aggregation that does the summing and then applying order by descending to that sum.
我试图通过应用另一个进行求和的聚合来对聚合结果进行排序,然后通过降序到该总和来应用顺序。
if I try like below, the aggregation result get sorted by doc count.
如果我尝试如下,聚合结果按doc count排序。
"order": {
"revrsenestedowners": "desc"
}
Below code explains the problem am facing. (field names are changed just to illustrate the problem)
下面的代码解释了我面临的问题。 (更改字段名称只是为了说明问题)
"machines" is my nested object but the "owners" is not nested and it belongs to parent object.
“machines”是我的嵌套对象,但“所有者”不是嵌套的,它属于父对象。
I need to get the top 10 machines name by owners machine count (require sum as the owners object are list and can have more than one value).
我需要按所有者机器计数获得前10名机器名称(需要总和,因为所有者对象是列表,并且可以有多个值)。
{
"query": {
"range": {
"createdDate": {
"gte": "2015-04-28T00:00:00",
"lte": "2015-05-01T23:59:59"
}
}
},
"aggs": {
"nestedagg": {
"nested": {
"path": "machines"
},
"aggs": {
"terms": {
"terms": {
"field": "machines.machineName",
"size": 10,
"order": {
"sumowners": "desc"
}
},
"aggs": {
"revrsenestedowners": {
"reverse_nested": {},
"aggs": {
"sumowners": {
"sum": {
"field": "owners.machinesCount"
}
}
}
}
}
}
}
}
}
}
I require the sum ordering and not the doc count ordering. for it to work I may require something like :
我需要总和排序而不是doc count排序。为了它的工作我可能需要这样的东西:
"order": {
"revrsenestedowners.sumowners": "desc"
}
Is there a way to achieve what I'm looking for.
有没有办法实现我正在寻找的东西。
Or Is this the limitation with elastic search? or a bug?
或者这是弹性搜索的限制?还是一个bug?
I'm stuck and really appreciate any help
我被困住了,非常感谢任何帮助
1 个解决方案
#1
I raised same issue on elastic search forum and they replied with the correct syntax,
我在弹性搜索论坛上提出了同样的问题,他们回答了正确的语法,
https://github.com/elastic/elasticsearch/issues/11059
The Answer is:
答案是:
"order": {
"revrsenestedowners > sumowners.value" : "desc"
}
Hope it may help to others,
希望它对其他人有帮助,
#1
I raised same issue on elastic search forum and they replied with the correct syntax,
我在弹性搜索论坛上提出了同样的问题,他们回答了正确的语法,
https://github.com/elastic/elasticsearch/issues/11059
The Answer is:
答案是:
"order": {
"revrsenestedowners > sumowners.value" : "desc"
}
Hope it may help to others,
希望它对其他人有帮助,