Query interactive demo

Run full-text, filter, aggregation, and location queries on a food delivery app's restaurants and orders, and see each redis-cli command and reply.

Redis Search lets you query data through an index you create. This demo uses restaurant and order data from a food delivery app, stored as hashes. It starts by showing the data and a possible index. Next, four kinds of queries are demonstrated: full-text search, filter and sort, aggregation, and location. For each query, it shows the command, the matching data, and the exact reply.

The demo runs in your browser and doesn't connect to Redis. Its commands and replies were recorded from Redis, and each command works as shown once you load the data and indexes into your own database. See Try it yourself. The restaurants and orders are the same sample data as the Redis Iris interactive demo.

What the demo shows

  1. The data. Each restaurant is a hash. An index, created with FT.CREATE, tells Redis Search which fields to search and how. See Indexing.
  2. Full-text search. FT.SEARCH finds words in TEXT fields, including other forms of each word, such as plurals. It also handles exact phrases, prefixes, fuzzy matches, and the |, -, and @field: operators. HIGHLIGHT marks the words that matched. See Full-text search.
  3. Filter and sort. TAG and NUMERIC fields take exact conditions, and conditions side by side must all match. SORTBY orders the matches. See Exact match queries and Range queries.
  4. Aggregate. FT.AGGREGATE groups the matching orders with GROUPBY and reduces each group with REDUCE, here with COUNT, SUM, and AVG. See Aggregation queries.
  5. Location. A GEO field holds a point, and a radius query finds the points within a given distance of a spot. A GEOSHAPE field holds a shape, such as a delivery zone, and CONTAINS finds the shapes that contain a point. See Geospatial queries.

Try it yourself

You can run the demo's queries against your own Redis database. First, load the sample data and the three indexes with the setup commands. Then copy a query from the demo with its Copy button, and run it.

You need Redis Open Source 8.0 or later, or Redis Stack 7.2 or later. Use an empty database, such as a free Redis Cloud database. The setup adds 19 hashes, with keys that start with restaurant: and order:, and three indexes.

The setup is 31 commands. Copy them from the tab for the tool you use:

FT.CREATE idx:restaurants ON HASH PREFIX 1 restaurant: SCHEMA name TEXT description TEXT cuisine TAG city TAG rating NUMERIC SORTABLE price_level NUMERIC SORTABLE avg_delivery_min NUMERIC SORTABLE
FT.CREATE idx:orders ON HASH PREFIX 1 order: SCHEMA customer_id TAG restaurant_id TAG status TAG total NUMERIC SORTABLE placed_ts NUMERIC SORTABLE items TEXT
FT.CREATE idx:places ON HASH PREFIX 1 restaurant: SCHEMA name TEXT SORTABLE location GEO delivery_zone GEOSHAPE
HSET restaurant:r201 name "Bangkok Street Kitchen" cuisine thai city austin rating 4.7 price_level 2 avg_delivery_min 30 description "Thai street food: pad thai, green and red curries, and tofu dishes, made spicy on request."
HSET restaurant:r202 name "Smokehouse 512" cuisine bbq city austin rating 4.4 price_level 3 avg_delivery_min 40 description "Texas barbecue: slow-smoked brisket, ribs, and mac and cheese."
HSET restaurant:r203 name "Green Bowl" cuisine vegan city seattle rating 4.8 price_level 2 avg_delivery_min 25 description "Plant-based bowls, salads, and smoothies. Everything on the menu is vegan."
HSET restaurant:r204 name "Sakura Sushi Bar" cuisine sushi city denver rating 4.6 price_level 3 avg_delivery_min 35 description "Fresh sushi and sashimi, nigiri sets, and miso soup."
HSET restaurant:r205 name "Nonna's Trattoria" cuisine italian city seattle rating 4.5 price_level 3 avg_delivery_min 45 description "Homemade pasta, risotto, and tiramisu from family recipes."
HSET restaurant:r206 name "Slice Society" cuisine pizza city denver rating 4.2 price_level 1 avg_delivery_min 30 description "New York-style pizza by the slice or the whole pie, made for sharing."
HSET restaurant:r207 name "Olive & Za'atar" cuisine mediterranean city austin rating 4.6 price_level 2 avg_delivery_min 30 description "Falafel, shawarma, hummus, and fresh salads from the eastern Mediterranean."
HSET restaurant:r208 name "Spice Route" cuisine indian city seattle rating 4.3 price_level 2 avg_delivery_min 40 description "Indian curries, chana masala, and tandoori, with plenty of fiery vegetarian dishes."
HSET restaurant:r209 name "Lotus Thai" cuisine thai city austin rating 4.1 price_level 1 avg_delivery_min 25 description "Thai curries and noodle dishes, known for its spicy green curry. Most dishes can be made vegetarian."
HSET order:o3001 customer_id u101 restaurant_id r201 status delivered total 34.5 placed_ts 1788375600 items "Pad thai with tofu, spring rolls"
HSET order:o3002 customer_id u101 restaurant_id r207 status delivered total 28 placed_ts 1789045200 items "Falafel wrap, hummus"
HSET order:o3003 customer_id u101 restaurant_id r209 status on_the_way total 22.75 placed_ts 1790272800 items "Green curry without fish sauce, jasmine rice"
HSET order:o3004 customer_id u102 restaurant_id r202 status delivered total 61.2 placed_ts 1788638400 items "Brisket platter, mac and cheese"
HSET order:o3005 customer_id u102 restaurant_id r201 status cancelled total 19.9 placed_ts 1787918400 items "Pad see ew"
HSET order:o3006 customer_id u103 restaurant_id r203 status delivered total 24 placed_ts 1789214400 items "Buddha bowl, oat latte"
HSET order:o3007 customer_id u103 restaurant_id r208 status delivered total 38.4 placed_ts 1789758000 items "Chana masala, garlic naan"
HSET order:o3008 customer_id u104 restaurant_id r206 status delivered total 42 placed_ts 1788724800 items "Two large pizzas"
HSET order:o3009 customer_id u104 restaurant_id r204 status delivered total 67.8 placed_ts 1789930800 items "Omakase set for two"
HSET order:o3010 customer_id u105 restaurant_id r205 status delivered total 54.3 placed_ts 1788897600 items "Mushroom risotto, tiramisu"
HSET restaurant:r201 location -97.7230,30.2640 delivery_zone "POLYGON((-97.6960 30.2640, -97.7067 30.2781, -97.7230 30.2899, -97.7402 30.2790, -97.7514 30.2640, -97.7383 30.2507, -97.7230 30.2370, -97.7048 30.2482, -97.6960 30.2640))"
HSET restaurant:r202 location -97.7500,30.2470 delivery_zone "POLYGON((-97.7136 30.2470, -97.7281 30.2660, -97.7500 30.2818, -97.7732 30.2671, -97.7882 30.2470, -97.7706 30.2291, -97.7500 30.2106, -97.7256 30.2257, -97.7136 30.2470))"
HSET restaurant:r203 location -122.3200,47.6200 delivery_zone "POLYGON((-122.2800 47.6200, -122.2960 47.6363, -122.3200 47.6498, -122.3454 47.6373, -122.3620 47.6200, -122.3426 47.6047, -122.3200 47.5888, -122.2931 47.6018, -122.2800 47.6200))"
HSET restaurant:r204 location -104.9990,39.7530 delivery_zone "POLYGON((-104.9639 39.7530, -104.9779 39.7693, -104.9990 39.7828, -105.0213 39.7703, -105.0358 39.7530, -105.0188 39.7377, -104.9990 39.7218, -104.9755 39.7348, -104.9639 39.7530))"
HSET restaurant:r205 location -122.3840,47.6680 delivery_zone "POLYGON((-122.3306 47.6680, -122.3519 47.6897, -122.3840 47.7078, -122.4180 47.6910, -122.4400 47.6680, -122.4142 47.6475, -122.3840 47.6264, -122.3482 47.6437, -122.3306 47.6680))"
HSET restaurant:r206 location -104.9780,39.7330 delivery_zone "POLYGON((-104.9675 39.7330, -104.9717 39.7379, -104.9780 39.7420, -104.9847 39.7382, -104.9890 39.7330, -104.9839 39.7284, -104.9780 39.7236, -104.9709 39.7275, -104.9675 39.7330))"
HSET restaurant:r207 location -97.7300,30.3050 delivery_zone "POLYGON((-97.7040 30.3050, -97.7144 30.3186, -97.7300 30.3299, -97.7466 30.3194, -97.7573 30.3050, -97.7447 30.2922, -97.7300 30.2790, -97.7125 30.2898, -97.7040 30.3050))"
HSET restaurant:r208 location -122.3380,47.6100 delivery_zone "POLYGON((-122.3047 47.6100, -122.3180 47.6236, -122.3380 47.6349, -122.3592 47.6244, -122.3730 47.6100, -122.3568 47.5972, -122.3380 47.5840, -122.3156 47.5948, -122.3047 47.6100))"
HSET restaurant:r209 location -97.7420,30.2690 delivery_zone "POLYGON((-97.7212 30.2690, -97.7295 30.2799, -97.7420 30.2889, -97.7552 30.2805, -97.7638 30.2690, -97.7538 30.2588, -97.7420 30.2482, -97.7280 30.2568, -97.7212 30.2690))"

Redis Insight

  1. Connect to your database in Redis Insight, and open Workbench.
  2. Paste the commands from the Redis Insight tab into the editor, and run them.
  3. Copy a query from the demo, paste it into Workbench, and run it. Workbench returns the same results as the demo, though it can lay them out as a table rather than as redis-cli prints them.

redis-cli

  1. Paste the command from the redis-cli tab into a terminal, and replace <host> and <port> with your database's. If your database needs a username and password, add --user <username> --pass <password> after the port.
  2. Run the command. It loads all 31 setup commands at once.
  3. Connect with redis-cli -h <host> -p <port>, add --user <username> --pass <password> if you used them in step 1, copy a query from the demo, and run it. The reply is the same as the demo's The output.

Clean up

To remove the sample data and the indexes, run these commands:

FT.DROPINDEX idx:places
FT.DROPINDEX idx:restaurants DD
FT.DROPINDEX idx:orders DD

DD deletes an index's hashes along with the index. idx:places covers the same restaurant hashes as idx:restaurants, so drop it first, without DD.

RATE THIS PAGE
Back to top ↑