Executing the terms aggregation
Terms aggregation is one of the most commonly used aggregations. It groups documents in buckets based on a single term value. This aggregation is often used to narrow down a search.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_06/executing_terms_aggregation.sh
) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
To execute a terms aggregation, we will perform the steps given as follows:
- We want to calculate the top-10 tags of all the documents; for this the REST call should be as follows:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&size=0' -d '{ "query": { "match_all": {} }, "aggs": { ...
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.