A calendar interval groups date-histogram buckets by calendar units, adjusting hours and days according to calendar settings such as daylight changes. section 13.3.1
Group book releases by year
Set calendar_interval to year when release dates should form one bucket per calendar year. The same interval can use the shorthand 1y. section 13.3.1
Listing 13.11 A date_histogram query
GET books/_search
{
"size":0,
"aggs": {
"release_year_histogram": {
"date_histogram": { #1
"field": "release_date", #2
"calendar_interval": "year" #3
}
}
}
}
This runnable query places release_date into yearly date-histogram buckets and returns document counts for each year. section 13.3.1
Choose supported calendar units according to the reporting period:
- Use year, quarter, month, week, day, hour, minute, second, or millisecond; single-unit forms such as 1M and 1d are also accepted. section 13.3.1
- Do not use multiples such as 5y or 4q; use fixed_interval when a fixed duration such as 730d is required. section 13.3.1
