Executing the top hit aggregation
The top hit aggregation is different from the other aggregation types. All the previous aggregations have metric (simple values) or bucket values; the top hit aggregation returns buckets of search hits.
Generally, the top hit aggregation is used as a subaggregation so that the top matching documents can be aggregated in buckets.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_06/executing_top_hit_aggregations.sh
) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
To execute a top hit aggregation, we will perform the steps given as follows:
- We want to aggregate the documents hits by tag (
tags
) and return only thename
field ...
Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.