I have an aggregation query here that is:
Return the number of Records by Type, grouped by Creator in the last 6 months.
The query is as follows:
GET /test/records/_search?search_type=count
{
"aggs": {
"timeRange": {
"filter": {
"range": {
"When": {
"gte": "now-6M",
"lte": "now"
}
}
},
"aggs": {
"groupBy": {
"terms": {
"field": "Creator",
"min_doc_count": 0
},
"aggs": {
"counts": {
"terms": {
"field": "Type",
"min_doc_count": 0
}
}
}
}
}
}
}
}
And the Results appear as:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 261,
"max_score": 0,
"hits": []
},
"aggregations": {
"timeRange": {
"doc_count": 192,
"groupBy": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "ff94d50a-9ced-4877-85cc-a08a00fd49f4",
"doc_count": 175,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 3,
"buckets": [
{
"key": "9f937783-dc28-421c-a937-a0c201643aae",
"doc_count": 95
},
{
"key": "36e4b200-e8ca-47f5-b9bb-a09101058595",
"doc_count": 31
},
{
"key": "cf421f05-37b1-470e-9ab9-a0bb0100792d",
"doc_count": 11
}
]
}
},
{
"key": "be8ca900-0011-0002-1976-c737a7e00000",
"doc_count": 0,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
},
{
"key": "fae866a8-705e-e111-bd17-d6ec07ced130",
"doc_count": 0,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
]
}
}
}
}
From the results listed above, it appears that when there is a 0 count in a terms aggregation, it won't bother listing 0s for the terms in levels below it.
My question is: Is it possible to have it show 0 counts for in these scenarios?
Example desired output below:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 261,
"max_score": 0,
"hits": []
},
"aggregations": {
"timeRange": {
"doc_count": 192,
"groupBy": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "ff94d50a-9ced-4877-85cc-a08a00fd49f4",
"doc_count": 175,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 3,
"buckets": [
{
"key": "9f937783-dc28-421c-a937-a0c201643aae",
"doc_count": 95
},
{
"key": "36e4b200-e8ca-47f5-b9bb-a09101058595",
"doc_count": 31
},
{
"key": "cf421f05-37b1-470e-9ab9-a0bb0100792d",
"doc_count": 11
}
]
}
},
{
"key": "be8ca900-0011-0002-1976-c737a7e00000",
"doc_count": 0,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "9f937783-dc28-421c-a937-a0c201643aae",
"doc_count": 0
},
{
"key": "36e4b200-e8ca-47f5-b9bb-a09101058595",
"doc_count": 0
},
{
"key": "cf421f05-37b1-470e-9ab9-a0bb0100792d",
"doc_count": 0
}
]
}
},
{
"key": "fae866a8-705e-e111-bd17-d6ec07ced130",
"doc_count": 0,
"counts": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "9f937783-dc28-421c-a937-a0c201643aae",
"doc_count": 0
},
{
"key": "36e4b200-e8ca-47f5-b9bb-a09101058595",
"doc_count": 0
},
{
"key": "cf421f05-37b1-470e-9ab9-a0bb0100792d",
"doc_count": 0
}
]
}
}
]
}
}
}
}