elasticsearch - Elastic Search filter with aggregate like Max or Min -
i have simple documents scheduleid. count of documents recent scheduleid. assuming max scheduleid recent, how write query. have been searching , reading few hours , work.
{ "aggs": { "max_schedule": { "max": { "field": "scheduleid" } } } }
that getting me max scheduleid , total count of documents out side of aggregate.
i appreciate if me on how take aggregate value , apply filter (like sub query in sql!).
this should it:
{ "aggs": { "max_scheduleid": { "terms": { "field": "scheduleid", "order" : { "_term" : "desc" }, "size": 1 } } } }
the terms aggregation give document counts each term, , works integers. need order results term instead of count (the default). , since want highest scheduleid
, "size":1
adequate.
here code used test it:
http://sense.qbox.io/gist/93fb979393754b8bd9b19cb903a64027cba40ece
Comments
Post a Comment