There are different ways to do this. One of them is to use a date_histogram
aggregation constrained by a filter that will only select the desired dates:
{
"aggs": {
"5_days": {
"filter": {
"filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"range": {
"date": {
"from": "2016-12-01T00:00:00.000Z",
"to": "2016-12-02T00:00:00.000Z"
}
}
},
{
"range": {
"date": {
"from": "2016-12-08T00:00:00.000Z",
"to": "2016-12-09T00:00:00.000Z"
}
}
},
{
"range": {
"date": {
"from": "2016-12-15T00:00:00.000Z",
"to": "2016-12-16T00:00:00.000Z"
}
}
},
{
"range": {
"date": {
"from": "2016-12-22T00:00:00.000Z",
"to": "2016-12-23T00:00:00.000Z"
}
}
},
{
"range": {
"date": {
"from": "2016-12-29T00:00:00.000Z",
"to": "2016-12-30T00:00:00.000Z"
}
}
}
]
}
}
},
"aggs": {
"samples": {
"date_histogram": {
"field": "date",
"interval": "day"
}
}
}
}
}
}
The second way is more concise and boils down to using a date_range
aggregation with only the selected dates:
{
"aggs": {
"range": {
"date_range": {
"field": "date",
"ranges": [
{ "from": "2016-12-01T00:00:00.000Z", "to": "2016-12-02T00:00:00.000Z" },
{ "from": "2016-12-08T00:00:00.000Z", "to": "2016-12-09T00:00:00.000Z" },
{ "from": "2016-12-15T00:00:00.000Z", "to": "2016-12-16T00:00:00.000Z" },
{ "from": "2016-12-22T00:00:00.000Z", "to": "2016-12-23T00:00:00.000Z" },
{ "from": "2016-12-29T00:00:00.000Z", "to": "2016-12-30T00:00:00.000Z" }
]
}
}
}
}