| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | [[search-aggregations-bucket-global-aggregation]]=== Global AggregationDefines a single bucket of all the documents within the search executioncontext. This context is defined by the indices and the document types you'researching on, but is *not* influenced by the search query itself.NOTE:   Global aggregators can only be placed as top level aggregators because        it doesn't make sense to embed a global aggregator within another        bucket aggregator.Example:[source,console,id=global-aggregation-example]--------------------------------------------------POST /sales/_search?size=0{  "query": {    "match": { "type": "t-shirt" }  },  "aggs": {    "all_products": {      "global": {}, <1>      "aggs": {     <2>      "avg_price": { "avg": { "field": "price" } }      }    },    "t_shirts": { "avg": { "field": "price" } }  }}--------------------------------------------------// TEST[setup:sales]<1> The `global` aggregation has an empty body<2> The sub-aggregations that are registered for this `global` aggregationThe above aggregation demonstrates how one would compute aggregations(`avg_price` in this example) on all the documents in the search context,regardless of the query (in our example, it will compute the average price overall products in our catalog, not just on the "shirts").The response for the above aggregation:[source,console-result]--------------------------------------------------{  ...  "aggregations": {    "all_products": {      "doc_count": 7, <1>      "avg_price": {        "value": 140.71428571428572 <2>      }    },    "t_shirts": {      "value": 128.33333333333334 <3>    }  }}--------------------------------------------------// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]<1> The number of documents that were aggregated (in our case, all documentswithin the search context)<2> The average price of all products in the index<3> The average price of all t-shirts
 |