So, I have a query for a date_histogram for which, if I set the interval to 1d, the response is:
"aggregations": {
"received": {
"buckets": [
{
"key_as_string": "2017-01-11T00:00:00.000Z",
"key": 1484092800000,
"doc_count": 2
},
{
"key_as_string": "2017-01-12T00:00:00.000Z",
"key": 1484179200000,
"doc_count": 1
},
{
"key_as_string": "2017-01-13T00:00:00.000Z",
"key": 1484265600000,
"doc_count": 2
}
]
}
}
The query for the above result is:
{
"size": 0,
"query": {
"bool": {
"must": [
<!----Omitted sensitive data---->
{
"range": {
"received": {
"gte": "1483228800000",
"lte": "1485907140000"
}
}
}
]
}
},
"aggs": {
"received": {
"date_histogram": {
"field": "received",
"interval": "1d"
}
}
}
}
The aggregations are
Problem is when I change the "interval" to "7d" the result is:
"aggregations": {
"received": {
"buckets": [
{
"key_as_string": "2017-01-05T00:00:00.000Z",
"key": 1483574400000,
"doc_count": 2
},
{
"key_as_string": "2017-01-12T00:00:00.000Z",
"key": 1484179200000,
"doc_count": 3
}
]
}
}
I expected the result to be the following since the search from Jan 1 to Jan 31 2017 and I want it to bucket for 7 days. So it should bucket Jan 1-Jan 7, Jan 8-Jan 14, Jan 15-Jan 21, ...:
"aggregations": {
"received": {
"buckets": [
{
"key_as_string": "2017-01-08T00:00:00.000Z",
"key": 1512691200000,
"doc_count": 5
}
]
}
}
Can someone explain me why that isn't the case and what is wrong with my understanding?