# Confusing DateHistogram behavior: buckets starts not from min bound date

**URL:** <https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343>\
**Category:** Elasticsearch\
**Created:** [May 27, 2017, 5:32pm UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343 "2017-05-27T17:32:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guchman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guchman/32/56121_2.png) [@Guchman](https://discuss.elastic.co/u/Guchman)\
**Post date:** [May 27, 2017, 5:32pm UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/1 "2017-05-27T17:32:52Z")

</div>

I'd already create [bug-report](https://github.com/elastic/elasticsearch/issues/24920)  
But maybe someone already know that issue workarounds.  
Merge days by 7days intervals in code is the last thing I want to do. But still doesn't find any other solution.

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 29, 2017, 8:34am UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/2 "2017-05-29T08:34:42Z")

</div>

The intervals are computed based on `1970-01-01` as the first bucket. This makes the bucketing consistent for the same interval. If you want to change this behavior you can use the `offset` option:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#\_offset](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#_offset)  
... or set the interval to `week`.  
The extended bounds are treated as if they were values from existing documents and not as already existing buckets.

---

<div class="post-metadata">

**Author:** ![varpa89](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@varpa89](https://discuss.elastic.co/u/varpa89)\
**Post date:** [May 31, 2017, 1:26pm UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/3 "2017-05-31T13:26:31Z")

</div>

Which offset value I should use to have date of first bucket equals to start date of my interval?

---

<div class="post-metadata">

**Author:** ![varpa89](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@varpa89](https://discuss.elastic.co/u/varpa89)\
**Post date:** [June 1, 2017, 11:38am UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/4 "2017-06-01T11:38:53Z")

</div>

If I use offset "+2d" for this example first bucket starts from 30 Nov 2017 but second starts from 02 Dec as expected and other next in 7 days.

---

<div class="post-metadata">

**Author:** ![varpa89](https://avatars.discourse-cdn.com/v4/letter/v/96bed5/32.png) [@varpa89](https://discuss.elastic.co/u/varpa89)\
**Post date:** [June 2, 2017, 6:34am UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/5 "2017-06-02T06:34:33Z")

</div>

If second bucket doesn't have any data offset doesn't work at all

---

<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:** [June 30, 2017, 6:35am UTC](https://discuss.elastic.co/t/confusing-datehistogram-behavior-buckets-starts-not-from-min-bound-date/87343/6 "2017-06-30T06:35:05Z")

</div>

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