I want my query to do this:
"Show me the last 28 days of some data, grouped in 7 day intervals"
I would expect to get 4 buckets, with each bucket representing one week of data for a total of 28 days. But instead, I am getting 5 buckets equivalent to 35 days.
My query looks like this:
{
"size": 0,
"aggs": {
"metrics:histogram": {
"date_histogram": {
"field": "some.timestamp",
"interval": "7d",
"min_doc_count": 0,
"extendedBounds": {
"min": 1490278007355,
"max": 1492693607355
}
},
"aggs": {}
}
},
"query": {
"filtered": {
"filter": {
"and": [
{
"range": {
"some.timestamp": {
"gt": 1490278007355,
"lte": 1492693607355
}
}
},
{
"terms": {
"some.array": [
123,
456,
789
]
}
}
]
}
}
}
}
My response looks like this:
{
"took": 26,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 72198,
"max_score": 0,
"hits": []
},
"aggregations": {
"metrics:histogram": {
"buckets": [
{
"key_as_string": "1490227200000",
"key": 1490227200000,
"doc_count": 0
},
{
"key_as_string": "1490832000000",
"key": 1490832000000,
"doc_count": 0
},
{
"key_as_string": "1491436800000",
"key": 1491436800000,
"doc_count": 273
},
{
"key_as_string": "1492041600000",
"key": 1492041600000,
"doc_count": 64681
},
{
"key_as_string": "1492646400000",
"key": 1492646400000,
"doc_count": 7244
}
]
}
}
}
As you can see, the first bucket is one week before the query filter and histogram extended bounds configuration.
Why is this? And how can I prevent it?
Many thanks.