Sorting after aggregation in Elasticsearch -
i have docs structure:
{ field1:string, field2: [ {subfield:number}, {subfield:number}...] }
i want sort on result of sum of numbers in field2.subfields:
get myindex/_search { "size":0, "aggs": { "a1": { "terms": { "field": "field1", "size":0 }, "aggs":{ "a2":{ "sum":{ "field":"field2.subfield" } } } } } }
if obtain buckets not sorted, want buckets sorted "a2" value. how can this? thank you!
you had it. need add order
property a1
terms aggregations, this:
get myindex/_search { "size":0, "aggs": { "a1": { "terms": { "field": "field1", "size":0, "order": {"a2": "desc"} <--- add }, "aggs":{ "a2":{ "sum":{ "field":"field2.subfield" } } } } } }
Comments
Post a Comment