Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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" }
      },
      "aggregations": {
        "query_age_avg": {
          "avg" : {
            "field" :  "age"
          }
        },
        "all_persons":{
          "global": {},
          "aggs":{
            "age_global_avg": {
              "avg" : {
                "field" :  "age"
         ...