Query data

Understand how to query, search, and aggregate Redis data

Redis Open Source distinguishes between the FT.SEARCH and FT.AGGREGATE query commands. You should use FT.SEARCH if you want to perform selections and projections only. If you also need to apply mapping functions, group, or aggregate data, use the FT.AGGREGATE command.

  • Selection: A selection allows you to return all documents that fulfill specific criteria.
  • Projection: Projections are used to return specific fields of the result set. You can also map/project to calculated field values.
  • Aggregation: Aggregations collect and summarize data across several fields.

Here is a short SQL comparison using the bicycle dataset:

TypeSQLRedis
SelectionSELECT * FROM bicycles WHERE price >= 1000FT.SEARCH idx:bicycle "@price:[1000 +inf]"
Simple projectionSELECT id, price FROM bicyclesFT.SEARCH idx:bicycle "*" RETURN 2 __key, price
Calculated projectionSELECT id, price-price*0.1 AS discounted FROM bicyclesFT.AGGREGATE idx:bicycle "*" LOAD 2 __key price APPLY "@price-@price*0.1" AS discounted
AggregationSELECT condition, AVG(price) AS avg_price FROM bicycles GROUP BY conditionFT.AGGREGATE idx:bicycle "*" GROUPBY 1 @condition REDUCE AVG 1 @price AS avg_price

The following articles provide an overview of how to query data with the FT.SEARCH command:

You can find further details about aggregation queries with FT.AGGREGATE in the following article:

RATE THIS PAGE
Back to top ↑