Range aggregation #
A multi-bucket aggregation over numeric fields where each bucket is a user-defined range.
Examples #
POST /sales/_search
{
"aggs": {
"price_ranges": {
"range": {
"field": "price",
"ranges": [
{ "to": 100 },
{ "from": 100, "to": 200 },
{ "from": 200 }
]
}
}
}
}
Response:
{
...
"aggregations": {
"price_ranges": {
"buckets": [
{ "key": "*-100.0", "to": 100.0, "doc_count": 2 },
{ "key": "100.0-200.0", "from": 100.0, "to": 200.0, "doc_count": 4 },
{ "key": "200.0-*", "from": 200.0, "doc_count": 1 }
]
}
}
}
Parameters for range
#
field
(Required, string) Field you wish to aggregate (must be numeric).ranges
(Required, array) Range definitions; each entry takes:key— (Optional, string) Range label; generated from the bounds when omitted.from— (Optional, number) Lower bound, inclusive. Omit for unbounded below.to— (Optional, number) Upper bound, exclusive. Omit for unbounded above.
aggs
(Optional, object) Nested sub-aggregations, computed per bucket.
For date fields, see the date_range aggregation.