我有这种结构的文档:
{ FIELD1:string, FIELD2: [ {SUBFIELD:number}, {SUBFIELD:number}...] }
我想对FIELD2.SUBFIELDs中的数字总和的结果进行排序:
GET myindex/_search { "size":0, "aggs": { "a1": { "terms": { "field": "FIELD1", "size":0 }, "aggs":{ "a2":{ "sum":{ "field":"FIELD2.SUBFIELD" } } } } } }
如果这样做,我将获得未排序的存储桶,但是我希望存储桶按“ a2”值进行排序。我该怎么做?谢谢!
你差点就吃了。你只需要一个添加order属性到你的a1条件聚合,是这样的:
order
a1
GET myindex/_search { "size":0, "aggs": { "a1": { "terms": { "field": "FIELD1", "size":0, "order": {"a2": "desc"} <--- add this }, "aggs":{ "a2":{ "sum":{ "field":"FIELD2.SUBFIELD" } } } } } }