# Getting different doc count for the same nested aggregation

**URL:** https://discuss.elastic.co/t/getting-different-doc-count-for-the-same-nested-aggregation/140488
**Category:** Elasticsearch
**Created:** [July 18, 2018, 8:53am UTC](https://discuss.elastic.co/t/getting-different-doc-count-for-the-same-nested-aggregation/140488 "2018-07-18T08:53:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![krishan](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@krishan](https://discuss.elastic.co/u/krishan)
#### Post date: [July 18, 2018, 8:53am UTC](https://discuss.elastic.co/t/getting-different-doc-count-for-the-same-nested-aggregation/140488/1 "2018-07-18T08:53:42Z")

</div>

**Below is my aggregation**

"aggregations": {  
"dealsMappedCatNested": {  
"nested": {  
"path": "deals"  
},  
"aggregations": {  
"dealsMappedCatFilter": {  
"filter": {  
"bool": {  
"filter": [{  
"exists":{  
"field":"deals.dealId"  
}  
},  
{  
"term": {  
"deals.categoryId": {  
"value": "SNM",  
"boost": 1  
}  
}  
},  
{  
"term": {  
"deals.state": {  
"value": "live",  
"boost": 1  
}  
}  
},  
{  
"term": {  
"deals.isSoldOut": {  
"value": false,  
"boost": 1  
}  
}  
}  
],  
"adjust\_pure\_negative": true,  
"boost": 1  
}  
},  
"aggregations": {  
"mappedCatNested": {  
"nested": {  
"path": "deals.mappedCategories"  
},  
"aggregations": {  
"mappedCatTerm": {  
"terms": {  
"field": "deals.mappedCategories.\_id",  
"size": 10,  
"min\_doc\_count": 1,  
"shard\_min\_doc\_count": 0,  
"show\_term\_doc\_count\_error": false,  
"order": [  
{  
"\_count": "desc"  
},  
{  
"\_key": "asc"  
}  
]  
}  
}  
}  
}  
}  
}  
}  
}  
}

**Results**

1. 

"dealsMappedCatNested": {  
"doc\_count": 749,  
"dealsMappedCatFilter": {  
"doc\_count": 486,  
"mappedCatNested": {  
"doc\_count": 1446,  
"mappedCatTerm": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 3,  
"buckets": [  
{  
"key": "20",  
"doc\_count": 159  
},  
{  
"key": "573acfce13db210aba60ccc5",  
"doc\_count": 118  
},  
{  
"key": "573ad08313db210aba60ccc7",  
"doc\_count": 103  
},  
{  
"key": "573ad08313db210aba60ccc8",  
"doc\_count": 29  
},  
{  
"key": "573ad08313db210aba60ccc9",  
"doc\_count": 25  
},  
{  
"key": "573acfce13db210aba60ccc6",  
"doc\_count": 22  
},  
{  
"key": "573ad08313db210aba60ccca",  
"doc\_count": 21  
},  
{  
"key": "573ad08313db210aba60cccb",  
"doc\_count": 19  
},  
{  
"key": "573ad08313db210aba60cccd",  
"doc\_count": 6  
},  
{  
"key": "573ad08313db210aba60cccc",  
"doc\_count": 5  
}  
]  
}  
}  
}  
}

1. 

"dealsMappedCatNested": {  
"doc\_count": 749,  
"dealsMappedCatFilter": {  
"doc\_count": 486,  
"mappedCatNested": {  
"doc\_count": 1446,  
"mappedCatTerm": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 6,  
"buckets": [  
{  
"key": "20",  
"doc\_count": 185  
},  
{  
"key": "573acfce13db210aba60ccc5",  
"doc\_count": 131  
},  
{  
"key": "573ad08313db210aba60ccc7",  
"doc\_count": 115  
},  
{  
"key": "573acfce13db210aba60ccc6",  
"doc\_count": 28  
},  
{  
"key": "573ad08313db210aba60cccb",  
"doc\_count": 28  
},  
{  
"key": "573ad08313db210aba60ccc8",  
"doc\_count": 26  
},  
{  
"key": "573ad08313db210aba60ccc9",  
"doc\_count": 23  
},  
{  
"key": "573ad08313db210aba60ccca",  
"doc\_count": 20  
},  
{  
"key": "573ad08313db210aba60ccce",  
"doc\_count": 9  
},  
{  
"key": "573ad08313db210aba60cccd",  
"doc\_count": 8  
}  
]  
}  
}  
}  
}

I think its related to the merging of results on the coordinating node.But it is creating issue with the final output for my application which is displayed to user.Can anyone tell how can i solve this ?

---

<div class="post-metadata">

### Author: ![krishan](https://avatars.discourse-cdn.com/v4/letter/k/e36b37/32.png) [@krishan](https://discuss.elastic.co/u/krishan)
#### Post date: [July 18, 2018, 10:14am UTC](https://discuss.elastic.co/t/getting-different-doc-count-for-the-same-nested-aggregation/140488/2 "2018-07-18T10:14:58Z")

</div>

If I remove filter from my aggregation it works fine.

---

<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: [August 15, 2018, 10:25am UTC](https://discuss.elastic.co/t/getting-different-doc-count-for-the-same-nested-aggregation/140488/3 "2018-08-15T10:25:56Z")

</div>

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