WARNING: Version 2.1 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Global Aggregation
editGlobal Aggregation
editDefines a single bucket of all the documents within the search execution context. This context is defined by the indices and the document types you’re searching on, but is not influenced by the search query itself.
Global aggregators can only be placed as top level aggregators (it makes no sense to embed a global aggregator within another bucket aggregator)
Example:
{ "query" : { "match" : { "title" : "shirt" } }, "aggs" : { "all_products" : { "global" : {}, "aggs" : { "avg_price" : { "avg" : { "field" : "price" } } } } } }
The |
|
The sub-aggregations that are registered for this |
The 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 over all products in our catalog, not just on the "shirts").
The response for the above aggregation: