A range query retrieves documents whose field values fall between lower and upper bounds. It works with numbers, dates, ratings, prices, and other structured attributes. section 2.4.2 section 9.6
Use these operators to define the range:
- `gt` means greater than; `gte` means greater than or equal to. section 9.6
- `lt` means less than; `lte` means less than or equal to. section 9.6
- Combine bounds to create inclusive or exclusive intervals, such as ratings from 9.0 through 9.5 or earnings greater than 350 and less than 400. section 9.6 section 5.5.3
- Apply ranges to dates, sort the results, or use date math such as `now-1y` and an anchor date followed by `||-2d`. section 9.6
Listing 9.13 Fetching movies with a specified range of ratings
GET movies/_search
{
"query": {
"range": {
"rating": {
"gte": 9.0,
"lte": 9.5
}
}
}
}
A focused JSON example retrieves movies with ratings from 9.0 to 9.5 using inclusive lower and upper bounds. section 9.6
Combine a range with other criteria
A Boolean query can require both a product match and a price range. For example, matching `TV` and requiring a price from 700 through 800 narrows the results to qualifying televisions. A range can also appear inside `must_not` to exclude values below a threshold, or inside `_delete_by_query` to remove documents in a range. section 11.3.3 section 2.5.3 section 5.5.3


