Executing an aggregation
ElasticSearch provides several functionalities other than search; it allows executing statistics and real-time analytics on searches via aggregations.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script, which is available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
To execute an aggregation, we will perform the steps given as follows:
- From the command line, we can execute a query with aggregations:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&size=0' -d '{ "query": { "match_all": {} }, "aggregations": { "tag": { "terms": { "field": "tag", "size": 10 } } } }'
In this case, we have used a
match_all
query plus a terms aggregation that is used to count terms. - The result returned by ElasticSearch, if everything is...