# ElasticSearch doc\_count not correct in nested aggregation

**URL:** https://discuss.elastic.co/t/elasticsearch-doc-count-not-correct-in-nested-aggregation/174001
**Category:** Elasticsearch
**Created:** [March 26, 2019, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-doc-count-not-correct-in-nested-aggregation/174001 "2019-03-26T19:23:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![psachida](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@psachida](https://discuss.elastic.co/u/psachida)
#### Post date: [March 26, 2019, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-doc-count-not-correct-in-nested-aggregation/174001/1 "2019-03-26T19:23:29Z")

</div>

I am having an issue with nested + term aggregations. I am searching for a keyword type field, the doc\_count in the aggregations is lesser than the expected count. In the example I have uploaded the  
--Bin Set--  
doc\_count = 65.

The --Bins-- is nested in --Bin Set--. Ideally, the sum(doc\_count) of all buckets should be equal to 65. i.e 17+17+15+7+3+1+1+1 should be equal to 65. But in my search query the count is less than 65(\<65). In other words, the doc\_count in the last level of aggregation is lesser than expected.

I have attached the index mapping, settings, query and result as images in the topic.

 ![aggregation-results](https://us1.discourse-cdn.com/elastic/original/3X/c/c/cc6af142f3128299cae3008079e2cc859eeae046.png) ![index-mapping](https://us1.discourse-cdn.com/elastic/original/3X/3/3/33a2a9a7ed7bd95aa3a658ae36d2beef99f0011c.png) ![index-settings](https://us1.discourse-cdn.com/elastic/original/3X/0/2/02ecd8aab267ebca4902ef3ecc6585171d8ce302.png) ![search-query](https://us1.discourse-cdn.com/elastic/original/3X/c/4/c4b8e67018b1c565a14beb4594f97e541f274b78.png)

---

<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: [April 23, 2019, 7:23pm UTC](https://discuss.elastic.co/t/elasticsearch-doc-count-not-correct-in-nested-aggregation/174001/2 "2019-04-23T19:23:46Z")

</div>

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