Top_hits

Top hits aggregation

/ Top_hits, / Aggregation

Top hits aggregation #

Keeps track of the most relevant documents being aggregated — useful inside a bucket aggregation (e.g. terms) to return the best-matching documents per bucket. Where most metric aggs reduce a bucket to one number, top_hits keeps the documents themselves.

How it works #

top_hits runs over a bucket’s document set and returns up to size documents in a hits envelope: hits.total — a plain count of the bucket’s documents — and hits.hits[], each entry carrying _id (the engine’s internal numeric document id) and _source.

...