Problem:
Demo the use of Global aggregations.
Solution Summary:
Global aggregations defines 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, not within a nested child aggregation.
Prerequisites:
Set up accounts index from accounts.json as explained in the link.
Solution Steps:
Case 0 - Without global Aggregation
GET accounts/_search
{
"query" : {
"exists": {
"field": "opening_date"
}
},
"aggs": {
"query_count": {
"value_count": {
"field": "_id"
}
}
},
"size": 0
}
Response contains:
...
"hits": {
"total": 10,
"max_score": 0,
"hits": []
},
"aggregations": {
"query_count": {
"value": 10
}
}
Case 1 - With Global Aggregation
GET accounts/_search
{
"query" : {
"exists": {
"field": "opening_date"
}
},
"aggs": {
"all_count": {
"global": {},
"aggs": {
"all_count_sub": {
"value_count": {
"field": "_id"
}
}
}
}
},
"size": 0
}
Response contains:
...
"hits": {
"total": 10,
"max_score": 0,
"hits": []
},
"aggregations": {
"all_count": {
"doc_count": 1000,
"all_count_sub": {
"value": 1000
}
}
}
}
Recent comments