...

/

Term-Level Queries: Range Query

Term-Level Queries: Range Query

Learn about the range query and how to utilize it.

Range query

A range query is a type of query that allows us to retrieve data within a specified range of values. It is used to filter data based on a range of values, such as numbers, dates, or strings. For example, we can perform a range query to retrieve all documents where the price field falls within the range of 20 to 50.

Range queries are often used in conjunction with other types of queries, such as search queries and aggregation queries. For example, we can perform a search query to find all the documents that contain the word "apple" and then perform a range query to filter the results by price. This allows us to find all documents that contain the word "apple" and have a price between 20 and 50.

Range queries can be very efficient because they only need to scan data within the specified range. This makes them a good choice for large datasets.

Range query syntax

To perform a range query, we can send a GET request to the _search endpoint of the target index. In the request body, we define the query using the range query type and specify its field name. Within the field name, we can set the range condition.

We can define the condition using the following values:

  • gt: Greater than
  • gte: Greater than or equal to
  • lt: Less than
  • lte:
...