Aggregation date_histogram and terms does not respect min_doc_count

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?

Noone? :slight_smile:

I think what you want here is a Filters Agg. 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.

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