As per the document for min_doc_count
Setting min_doc_count=0 will also return buckets for terms that didn’t match any hit. However, some of the returned terms which have a document count of zero might only belong to deleted documents or documents from other types, so there is no warranty that a match_all query would find a positive document count for those terms.
Is there any way to return only the matching buckets and if not part of the cluster fill with 0.
{
"aggs": {
"matching_term": {
"filter": {
"query": {
"bool": {
"must": [
{
"terms": {
"test_filed": [
"a",
"b",
"c",
"d",
"e",
"f"
]
}
}
]
}
}
},
"aggs": {
"time": {
"date_histogram": {
"field": "time",
"interval": "2h",
"min_doc_count": 0
},
"aggregations": {
"test_filed": {
"terms": {
"field": "test_filed",
"shard_size": 0,
"min_doc_count": 0,
"size": 5
},
"aggregations": {
"test_filed_value": {
"sum": {
"field": "test_filed_value"
}
}
}
}
}
}
}
}
}
}
Actaul response is as below for an bucket
{
"key_as_string" : "2016-06-21T20:00:00.000Z",
"key" : 1466539200000,
"doc_count" : 5949,
"test_filed" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "a",
"doc_count" : 5949,
"total_bytes" : {
"value" : 3.0950937E7
}
}, {
"key" : "b",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "x",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "y",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "z",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
} ]
}
}
but the expected response is
{
"key_as_string" : "2016-06-21T20:00:00.000Z",
"key" : 1466539200000,
"doc_count" : 5949,
"test_filed" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "a",
"doc_count" : 5949,
"total_bytes" : {
"value" : 3.0950937E7
}
}, {
"key" : "b",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "d",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "e",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
}, {
"key" : "f",
"doc_count" : 0,
"total_bytes" : {
"value" : 0.0
}
} ]
}
}
So how can I restrict the bucket to the matching term?