A range filter in an Elasticsearch query is used to filter documents based on a specific numeric or date field falling within a specified range of values. This filter allows you to retrieve documents that meet certain criteria within a specified range.
When dealing with numeric fields (e.g., prices, quantities), you can use a range filter to find documents where the field value falls within a specified numeric range.
Example:
{
"range": {
"price": {
"gte": 20,
"lte": 50
}
}
}
For date fields (e.g., timestamps, dates of events), you can use a range filter to filter documents within a specified date range.
Example:
{
"range": {
"event_date": {
"gte": "2023-01-01",
"lte": "2023-12-31"
}
}
}