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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -