The date_range aggregation query defines a set of date-ranges that represents a bucket. Only documents with properties of type ‘DateTime’ will considered in the date_range aggregation buckets. Here’s a list of properties:

field (string)
The property path.
format (string)
The date-format of which the buckets will be formatted to on return. Default to YYYY-MM-DDThh:mm:ssTZD.
ranges (range[])
The range-buckets to create.
range (from: number, to: number)
Defines a range to create a bucket for. From-value is included in bucket, to is excluded. The from and to follows a special date-math explained below.

Here’s an example of the date_range aggregation:

"my_date_range": {
  "date_range": {
    "field": "date",
    "format": "MM-yyy",
    "ranges": [{
      "to": "now-10M"
      "from": "now-10M"

The above example gives the following result:

"price_ranges": {
  "buckets": [{
    "doc_count": 2,
    "key": "a",
    "to": 50
    "doc_count": 4,
    "from": 50,
    "key": "b",
    "to": 100
    "doc_count": 4,
    "from": 100,
    "key": "c"

Date-math expression

The range fields accepts a date-math expression to calculate the time-spans.

Now minus a day:


The given date minus 3 days plus one minute:


Range describing now plus one day and thirty minutes, rounded to minutes: