# Can you do date histogram with specified number of buckets?

**URL:** <https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18300>\
**Category:** Elasticsearch\
**Created:** [June 24, 2014, 4:30pm UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18300 "2014-06-24T16:30:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnrodey](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@johnrodey](https://discuss.elastic.co/u/johnrodey)\
**Post date:** [June 24, 2014, 4:30pm UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18300/1 "2014-06-24T16:30:28Z")

</div>

Looks like the histogram aggregation works currently where each bucket is based on a user defined time interval, therefore you do not know how many buckets you will be returned unless you know ahead of time how much time your data spans.

Is there a way to create a date histogram aggregation in ElasticSearch where I can define the number of buckets that I want and the bucket increment be determined during execution based on the oldest and newest matching document?

I would like to be able to say give me 20 buckets. Thus if the data spans 10 years each bucket is determined a half year, or if it spans 10 minutes each bucket determined to be 30 seconds.

Thanks!

---

<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 6, 2017, 1:20am UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18300/2 "2017-07-06T01:20:07Z")

</div>


