# Aggregation date\_histogram and terms does not respect min\_doc\_count

**URL:** <https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637>\
**Category:** Elasticsearch\
**Created:** [October 15, 2019, 11:44am UTC](https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637 "2019-10-15T11:44:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thernstig](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@thernstig](https://discuss.elastic.co/u/thernstig)\
**Post date:** [October 15, 2019, 11:44am UTC](https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637/1 "2019-10-15T11:44:02Z")

</div>

I am using an aggregation that looks something like this:

```
  "aggs": {
    "dates": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "1h"
      },
      "aggs": {
        "birds": {
          "terms": {
            "field": "birds.keyword",
            "min_doc_count": 0
          }
        }
      }
    }
  }

```

The birds contain e.g. hawk, eagle and duck.

I was expecting the dates that had no "hawk" sightings to return hawk: 0 as a result, but the date buckets do not list the term in case it has 0. I thought this was what min\_doc\_count was for but it does not work. What's wrong?

---

<div class="post-metadata">

**Author:** ![thernstig](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@thernstig](https://discuss.elastic.co/u/thernstig)\
**Post date:** [October 21, 2019, 6:59pm UTC](https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637/2 "2019-10-21T18:59:31Z")

</div>

Noone? 🙂

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [October 21, 2019, 7:32pm UTC](https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637/3 "2019-10-21T19:32:36Z")

</div>

I think what you want here is a [Filters Agg](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html). Within the given time range bucket, if there are no docs with "hawk" in the key field, the terms agg doesn't "know" to create a bucket.

---

<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:** [November 18, 2019, 7:32pm UTC](https://discuss.elastic.co/t/aggregation-date-histogram-and-terms-does-not-respect-min-doc-count/203637/4 "2019-11-18T19:32:41Z")

</div>

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