# Date Histogram for dynamic Date Ranges

**URL:** <https://discuss.elastic.co/t/date-histogram-for-dynamic-date-ranges/75091>\
**Category:** Elasticsearch\
**Created:** [February 14, 2017, 6:40pm UTC](https://discuss.elastic.co/t/date-histogram-for-dynamic-date-ranges/75091 "2017-02-14T18:40:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irina](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@Irina](https://discuss.elastic.co/u/Irina)\
**Post date:** [February 14, 2017, 6:40pm UTC](https://discuss.elastic.co/t/date-histogram-for-dynamic-date-ranges/75091/1 "2017-02-14T18:40:57Z")

</div>

My documents’ structure is in the following form:  
{ "id" : 1, "item" : "A", "state" : "new", "created" : "2017-01-02" , "changed" : "2017-01-04"}  
{ "id" : 2, "item" : "B", "state" : "active", "created" : "2017-01-05", "changed" : "2017-01-09" }  
{ "id" : 3, "item" : "C", "state" : "validated", "created" : "2017-01-10", "changed" : "2017-01-11" }

How I can construct Date Histogram to show the items count per every day within the date range from “created” to “ changed” dates. If Date Histogram aggregation works for a single date and returns the count of items per a single date only, so what an alternative solution can be implemented in this case?  
{  
"aggs" : {  
"items\_over\_time" : {  
"date\_histogram" : {  
"field" : "created",  
"interval" : "1D",  
"format" : "yyyy-MM-dd"  
}  
}  
}  
}

This query returns the count per created date :  
"aggregations":{  
"items\_over\_time":{  
"buckets":[  
{  
"key\_as\_string":"2017-01-02",  
"key":1483315200000,  
"doc\_count":1  
},  
{  
"key\_as\_string":"2017-01-03",  
"key":1483401600000,  
**"doc\_count":0**  
},  
{  
"key\_as\_string":"2017-01-04",  
"key":1483488000000,  
**"doc\_count":0**  
},  
{  
"key\_as\_string":"2017-01-05",  
"key":1483574400000,  
"doc\_count":1  
},  
{  
"key\_as\_string":"2017-01-06",  
"key":1483660800000,  
"doc\_count":0  
},  
{  
"key\_as\_string":"2017-01-07",  
"key":1483747200000,  
"doc\_count":0  
},  
{  
"key\_as\_string":"2017-01-08",  
"key":1483833600000,  
"doc\_count":0  
},  
{  
"key\_as\_string":"2017-01-09",  
"key":1483920000000,  
"doc\_count":0  
},  
{  
"key\_as\_string":"2017-01-10",  
"key":1484006400000,  
"doc\_count":1  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [February 15, 2017, 11:00am UTC](https://discuss.elastic.co/t/date-histogram-for-dynamic-date-ranges/75091/2 "2017-02-15T11:00:21Z")

</div>

If you are wanting to have the histogram count all time between the created and changed values you might be interested in this topic that was asking a similar thing: [Display concurrency in data on Kibana](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/3)

I think the solution suggested there should work for you too?

---

<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:** [March 15, 2017, 11:00am UTC](https://discuss.elastic.co/t/date-histogram-for-dynamic-date-ranges/75091/3 "2017-03-15T11:00:22Z")

</div>

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