Terms Aggregation and get latest document


I am currently performing a search api call and that aggregates on a field and this works great, it gives me a list of terms and a count of those terms.

How would I go about supplementing the search response, with a selected number of fields from the latest document that was within the aggregate.

To get something roughly equivalent to

Term: TermA, Count: 50, Latest Field A: sunny, Latest Field B: 15degrees

If you need latest document in the bucket, how about using top_hits aggregation? It is also possible to filter source by _source option.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.