# Aggregation by date

**URL:** https://discuss.elastic.co/t/aggregation-by-date/33469
**Category:** Elasticsearch
**Created:** [November 1, 2015, 4:48pm UTC](https://discuss.elastic.co/t/aggregation-by-date/33469 "2015-11-01T16:48:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kashk](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kashk](https://discuss.elastic.co/u/kashk)
#### Post date: [November 1, 2015, 4:48pm UTC](https://discuss.elastic.co/t/aggregation-by-date/33469/1 "2015-11-01T16:48:16Z")

</div>

Hi,

I'm looking for bucket aggregation that can be applied on date time values, so I can create buckets on date field where the time between each two results is less than an hour.

For example, if I have the following:  
"key\_as\_string": 2015-10-06T10:05:00.000Z  
"key\_as\_string": 2015-10-06T10:55:00.000Z  
"key\_as\_string": 2015-10-06T11:15:00.000Z  
"key\_as\_string": 2015-10-06T12:25:00.000Z

I expect to get 2 buckets:

The first bucket will include 3 results:  
2015-10-06T10:05:00.000Z  
2015-10-06T10:55:00.000Z  
2015-10-06T11:15:00.000Z

The second bucket will include 1 result:  
2015-10-06T12:25:00.000Z

I tried the date histogram aggregation but using the hour interval creates an extra bucket for the result in 11:15 , and that’s not what I need.

Any ideas how this can be done?

Thanks

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 1, 2015, 9:01pm UTC](https://discuss.elastic.co/t/aggregation-by-date/33469/2 "2015-11-01T21:01:16Z")

</div>

I don't think you can do this with aggs, because as you found out, it does it based on the hour and not a range.  
I'm not sure what else you could do though sorry, someone else might have an idea.

---

<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:41pm UTC](https://discuss.elastic.co/t/aggregation-by-date/33469/3 "2017-07-05T23:41:25Z")

</div>


