# Date histogram omitting buckets

**URL:** <https://discuss.elastic.co/t/date-histogram-omitting-buckets/311209>\
**Category:** Elasticsearch\
**Created:** [August 2, 2022, 11:39am UTC](https://discuss.elastic.co/t/date-histogram-omitting-buckets/311209 "2022-08-02T11:39:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thahgr](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@thahgr](https://discuss.elastic.co/u/thahgr)\
**Post date:** [August 2, 2022, 11:39am UTC](https://discuss.elastic.co/t/date-histogram-omitting-buckets/311209/1 "2022-08-02T11:39:47Z")

</div>

I am trying to get a result like the kibana "discover" tab like below

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/7/3790d286efdea0037b7b1c126066878aed2510a9.png)

via **date\_histogram** functionality

my request is as below

```auto
GET index-*/_search
{
  "size": 0,
  "aggs": {
    "stats": {
      "date_histogram": {
        "min_doc_count": 0,
        "missing": 0, 
        "time_zone": "+03:00",
        "field": "@timestamp",
        "fixed_interval": "1h",
        "format": "yyyy-MM-dd HH:mm:ss"
      }
    }
  },
    "query": {
    "bool": {
      "filter": {
        "range": {
          "@timestamp": {
              "format": "strict_date_optional_time",
              "gte": "2022-08-01T11:00:00.000Z",
              "lte": "2022-08-02T11:14:34.158Z"
          }
        }
      }
    }
  }
}

```

resulting in correct query verifying from the number of total hits

```auto
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 6,
    "successful": 6,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 782,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "stats": {
      "buckets": [
        {
          "key_as_string": "2022-08-01 14:00:00",
          "key": 1659351600000,
          "doc_count": 450
        },
        {
          "key_as_string": "2022-08-01 15:00:00",
          "key": 1659355200000,
          "doc_count": 265
        },
...................................
        {
          "key_as_string": "2022-08-02 09:00:00",
          "key": 1659420000000,
          "doc_count": 0
        },
        {
          "key_as_string": "2022-08-02 10:00:00",
          "key": 1659423600000,
          "doc_count": 31
        },
        {
          "key_as_string": "2022-08-02 11:00:00",
          "key": 1659427200000,
          "doc_count": 0
        },
        {
          "key_as_string": "2022-08-02 12:00:00",
          "key": 1659430800000,
          "doc_count": 1
        }
      ]
    }
  }
}

```

**the problem is that it does not return empty buckets that are in the end even if `min_doc_count` is set to 0. The number of buckets is 23 not 24 and only the last non-empty bucket is returned**

If the last bucket is not empty then 24 are shown correctly. The in-between empty buckets are shown correctly to 0.

how can I fix my missing buckets ? Maybe its not possible with date\_histogram ?

Thanks

---

<div class="post-metadata">

**Author:** ![thahgr](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@thahgr](https://discuss.elastic.co/u/thahgr)\
**Post date:** [August 30, 2022, 10:41am UTC](https://discuss.elastic.co/t/date-histogram-omitting-buckets/311209/2 "2022-08-30T10:41:39Z")

</div>

somebody replied correctly on stack overflow, you can close the ticket

> <https://stackoverflow.com/questions/73206956/elasticsearch-date-histogram-omits-buckets/73207247#73207247>

---

<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:** [September 27, 2022, 10:41am UTC](https://discuss.elastic.co/t/date-histogram-omitting-buckets/311209/3 "2022-09-27T10:41:43Z")

</div>

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