liveBook · Manning

Calendar interval

As explained in Elasticsearch in Action, Second Edition

A calendar interval is a date histogram interval interpreted according to calendar units and calendar-aware date adjustments.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines calendar adjustment, accepted units, shorthand, and invalid multiples, while contrasting fixed durations.
Examples
Uses yearly book-release buckets and contrasts them with a 730-day fixed interval.
What it assumes
Assumes date-histogram aggregation basics and teaches calendar-aware versus fixed-duration interval selection.
What you can do after
Configure date-histogram aggregations with valid calendar units and choose fixed intervals when calendar awareness is unnecessary.
How it connects
Connects date histogram, fixed interval, calendar units, and daylight-saving adjustments.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.