0

I have terms aggregation and I need sort result buckets by another field (date). Or I need to add 2 sub aggregations with max (and top hit) and min (and top hit).

I didn't find any API that allows me to do this.

I think I can add max subAggregation with top hit for the main terms aggregation, and create another terms aggregation with min with top hits sub aggregation, but it will be so heavy job.

4
  • When you do terms aggregation, each term bucket may have more than one record of data. How are you gonna sort the buckets with date field? Commented Aug 11, 2016 at 21:58
  • If you want to sort them by max date, its called sorting on deep metrics. "terms": { "field": "xxxxxx", "size" : 10, "order": { "aggre1>most_recent":"desc" } } Commented Aug 11, 2016 at 22:05
  • @QiTang I have topHits subAggregation. I meant I need to sort that buckets. And how can I specify date field name which will be used to sort? Commented Aug 12, 2016 at 7:13
  • maybe you can do this "orders" : { "top_hits": { "sort": [ { "time_placed": { "order": "desc" } } ], "size" : 3 } If you want to do sorting inside each bucket Commented Aug 12, 2016 at 13:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.