Executing the global aggregation

Aggregations are generally executed on query search results, ElasticSearch provides a special aggregation—global—that is executed globally on all the documents without being influenced by the query.

Getting ready

You need a working ElasticSearch cluster and an index populated with the script (executing_global_aggregations.sh) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.

How to do it...

To execute global aggregations, we will perform the steps given as follows:

  1. If we want to compare a global average with a query one, the call will be something like this:
    curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?size=0&pretty=true' -d '
    {
      "query": {
        "term" : { "tag" : "ullam" }

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.