content/develop/ai/search-and-query/query/range.md
A range query on a numeric field returns the values that are in between a given start and end value:
FT.SEARCH index "@field:[start end]"
You can also use the FILTER argument, but you need to know that the query execution plan is different because the filter is applied after the query string (e.g., *) is evaluated:
FT.SEARCH index "*" FILTER field start end
Start and end values are by default inclusive, but you can prepend ( to a value to exclude it from the range.
The values -inf, inf, and +inf are valid values that allow you to define open ranges.
An open-range query can lead to a large result set.
By default, [FT.SEARCH]({{< relref "commands/ft.search/" >}}) returns only the first ten results. The LIMIT argument helps you to scroll through the result set. The SORTBY argument ensures that the documents in the result set are returned in the specified order.
FT.SEARCH index "@field:[start end]" SORTBY field LIMIT page_start page_end
You can find further details about using the LIMIT and SORTBY in the [FT.SEARCH]({{< relref "commands/ft.search/" >}}) command reference.
The examples in this section use a schema with the following fields:
| Field name | Field type |
|---|---|
price | NUMERIC |
The following query finds bicycles within a price range greater than or equal to 500 USD and smaller than or equal to 1000 USD (500 <= price <= 1000):
{{< clients-example set="query_range" step="range1" description="Foundational: Query numeric fields with inclusive range syntax when you need to find documents with values between two bounds" difficulty="beginner" >}}
FT.SEARCH idx:bicycle "@price:[500 1000]"
This is semantically equivalent to:
{{< clients-example set="query_range" step="range2" description="Foundational: Query numeric fields using a FILTER clause when you need an alternative syntax for range queries with different query execution semantics" difficulty="beginner" >}}
FT.SEARCH idx:bicycle "*" FILTER price 500 1000
For bicycles with a price greater than 1000 USD (price > 1000), you can use:
{{< clients-example set="query_range" step="range3" description="Open ranges: Query numeric fields with open ranges using infinity notation and exclusive bounds when you need to find documents above or below a threshold" difficulty="intermediate" >}}
FT.SEARCH idx:bicycle "@price:[(1000 +inf]"
The example below returns bicycles with a price lower than or equal to 2000 USD (price <= 2000) by returning the five cheapest bikes:
{{< clients-example set="query_range" step="range4" description="Sorting and pagination: Combine range queries with SORTBY and LIMIT to retrieve sorted results in pages when you need to handle large result sets efficiently" difficulty="intermediate" >}}
FT.SEARCH idx:bicycle "@price:[-inf 2000]" SORTBY price LIMIT 0 5
You can learn more about non-numeric range queries, such as [geospatial]({{< relref "/develop/ai/search-and-query/query/geo-spatial" >}}) or [vector search]({{< relref "/develop/ai/search-and-query/query/vector-search" >}}) queries, in their dedicated articles.