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:

  1. 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 ...

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.