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.

Squeez
  • 919
  • 2
  • 12
  • 30
  • 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? – Qi Tang Aug 11 '16 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" } } – Qi Tang Aug 11 '16 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? – Squeez Aug 12 '16 at 07: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 – Qi Tang Aug 12 '16 at 13:49

0 Answers0