When a range query is executed in Elasticsearch, it searches for documents that contain a value within a specified range. The range can be specified using one or more of the following parameters:
– `gte` (greater than or equal to): Specifies the lower bound of the range, inclusive.
– `gt` (greater than): Specifies the lower bound of the range, exclusive.
– `lte` (less than or equal to): Specifies the upper bound of the range, inclusive.
– `lt` (less than): Specifies the upper bound of the range, exclusive.
The range query can be used with fields that contain numeric, date, or string values. When used with numeric or date values, the range query performs a numeric or date comparison to determine whether the value falls within the specified range. When used with string values, the range query performs a lexicographic comparison based on the Unicode code points of the characters.
Here’s an example of a range query that searches for documents with a `price` field between 10 and 100, inclusive:
GET /my_index/_search { "query": { "range": { "price": { "gte": 10, "lte": 100 } } } }
In this example, the range query specifies that the `price` field must be greater than or equal to 10 and less than or equal to 100. The query returns any documents that contain a value in the `price` field that falls within this range.
The range query can also be used in combination with other query types, such as the bool query, to construct more complex search queries. By allowing for searching for values within a specific range, the range query provides a powerful and flexible way to search for values in Elasticsearch.