A range query is a query type in Elasticsearch that is used to search for documents that contain a value within a specified range. It can be used with numeric, date, or string fields.
The range query is often used for searching fields that contain values that can be compared numerically or by their order, such as dates or prices. It allows for searching for documents that contain values within a specific range, such as all documents with prices between $10 and $100.
Here’s an example of a range query in Elasticsearch:
GET /my_index/_search { "query": { "range": { "price": { "gte": 10, "lte": 100 } } } }
In this example, we are searching the `price` field in the `my_index` index for values that are between 10 and 100. The range query will return any documents that contain a value in the `price` field that is within this range.
The range query supports a variety of options, such as specifying whether the range is inclusive or exclusive and whether the values should be formatted using a specific date format. This allows for more fine-grained control over the search results.
Overall, the range query provides a powerful and flexible way to search for values within a specific range in Elasticsearch, making it well-suited for searching fields that contain numeric or ordered values.