# Bucket Aggregation with min\_doc\_count: 0 returns old/non existent keys

**URL:** <https://discuss.elastic.co/t/bucket-aggregation-with-min-doc-count-0-returns-old-non-existent-keys/148978>\
**Category:** Elasticsearch\
**Created:** [September 18, 2018, 12:30pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-min-doc-count-0-returns-old-non-existent-keys/148978 "2018-09-18T12:30:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yahuu](https://avatars.discourse-cdn.com/v4/letter/y/90db22/32.png) [@yahuu](https://discuss.elastic.co/u/yahuu)\
**Post date:** [September 18, 2018, 12:30pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-min-doc-count-0-returns-old-non-existent-keys/148978/1 "2018-09-18T12:30:46Z")

</div>

Hello,

I am using a bucket aggregation with min\_doc\_count: 0  
The results are keys that are not present in the database (were deleted).

Where does the bucket aggregation get these keys from.

Here my example (the keys "2.99.0.0\n" and "2.88.0.0\n" do not exist in any docs anymore)

My query:

{  
"size": 0,  
"\_source": {  
"excludes": []  
},  
"aggs": {  
"2": {  
"terms": {  
"field": "fileversion.keyword",  
"size": 10,  
"order": {  
"\_term": "desc"  
},  
"min\_doc\_count": 0  
}  
}  
},  
"stored\_fields": [  
"\*"  
],  
"script\_fields": {},  
"docvalue\_fields": [  
"@timestamp"  
],  
"query": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
},  
{  
"range": {  
"@timestamp": {  
"gte": 1514761200000,  
"lte": 1546297199999,  
"format": "epoch\_millis"  
}  
}  
}  
],  
"filter": [],  
"should": [],  
"must\_not": []  
}  
}  
}

Response:

{  
"took": 18,  
"timed\_out": false,  
"\_shards": {  
"total": 131,  
"successful": 131,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 88079471,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"2": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 68872185,  
"buckets": [  
{  
"key": "2.99.0.0\n",  
"doc\_count": 0  
},  
{  
"key": "2.88.0.0\n",  
"doc\_count": 0  
},  
{  
"key": "2.8.0.14533",  
"doc\_count": 88524  
}  
]  
}  
},  
"status": 200  
}

I hope my explanation is sufficient.  
Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 16, 2018, 12:39pm UTC](https://discuss.elastic.co/t/bucket-aggregation-with-min-doc-count-0-returns-old-non-existent-keys/148978/2 "2018-10-16T12:39:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
