# Wrong doc\_count values for all buckets when using the 'missing' parameter in terms aggr!

**URL:** <https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331>\
**Category:** Elasticsearch\
**Created:** [January 4, 2016, 4:12pm UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331 "2016-01-04T16:12:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nir\_Reuveny](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nir\_Reuveny](https://discuss.elastic.co/u/Nir_Reuveny)\
**Post date:** [January 4, 2016, 4:12pm UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/1 "2016-01-04T16:12:15Z")

</div>

We're trying to use the new 'missing' param in terms aggr in both ES 2.1 and 2.11 clusters and the doc\_count values returned (not just for the 'missing' documents) are different compared to the same aggr without the missing param!

I would expect all the buckets to be the same doc\_count values and just an additional bucket with the doc\_count of those documents without this field... I can't explain why adding this missing param is returning different values for the rest of the buckets...

Any ideas? Seems like a serious bug...

(I tried to create a test index with just 5 documents and it seems to work ok there... but we have the problem with bigger indexes even an index with 3,000 docs)

{  
"size": 0,  
"aggs": {  
"2": {  
"terms": {  
"field": "fieldname",  
"size": 100,  
"missing": "Test"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 5, 2016, 4:18pm UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/2 "2016-01-05T16:18:17Z")

</div>

I think you are seeing one of the bugs that this PR fixes: [https://github.com/elastic/elasticsearch/pull/15746](https://github.com/elastic/elasticsearch/pull/15746)

For now you should be able to work around this by adding `"execution_mode": "global_ordinals"` to your terms aggregation,

Let me know if that workaround fixes your issue.

---

<div class="post-metadata">

**Author:** ![Nir\_Reuveny](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nir\_Reuveny](https://discuss.elastic.co/u/Nir_Reuveny)\
**Post date:** [January 7, 2016, 8:29am UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/3 "2016-01-07T08:29:09Z")

</div>

Hi,

Just tried this and it gave me an error...

```
    "type": "search_parse_exception",
    "reason": "Unknown key for a VALUE_STRING in [2]: [execution_mode]."
```

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 7, 2016, 8:34am UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/4 "2016-01-07T08:34:28Z")

</div>

Sorry I got the wrong name for the setting, it should be `"execution_hint": "global_ordinals"`. see [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-execution-hint) for more details on this setting

---

<div class="post-metadata">

**Author:** ![Nir\_Reuveny](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nir\_Reuveny](https://discuss.elastic.co/u/Nir_Reuveny)\
**Post date:** [January 7, 2016, 9:41am UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/5 "2016-01-07T09:41:01Z")

</div>

Thanks! that seems to work now...

---

<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:** [July 5, 2017, 11:26pm UTC](https://discuss.elastic.co/t/wrong-doc-count-values-for-all-buckets-when-using-the-missing-parameter-in-terms-aggr/38331/6 "2017-07-05T23:26:27Z")

</div>


