rangeΒΆ

The range aggregation query defines a set of ranges that represents a bucket. Here’s a list of properties:

field (string)
The property path.
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.

Here’s an example of the range aggregation:

"price_ranges": {
  "range": {
    "field": "price",
    "ranges": [
      { "to": 50 },
      { "from": 50, "to": 100 },
      { "from": 100 }
    ]
  }
}

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"
  }]
}