Date Histogram for dynamic Date Ranges

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
}
]
}

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

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

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