Indexing interactive demo
Change an index's field types, prefixes, and options, and see what each query finds, with every redis-cli command and reply.
Redis Search only finds data that's in an index. You create an index with FT.CREATE, which says which keys to include and how to treat each of their fields, and Redis keeps it up to date as the data changes. How you define the index decides what queries can find.
This demo starts with the data itself, the restaurants of a food delivery app, then creates an index on it and lets you change it: the field types, the keys it covers, how it handles missing and invalid values, and whether the restaurants are hashes or JSON documents. For each change, it shows the commands, the stored data, and which restaurants the query finds.
The demo runs in your browser and doesn't connect to Redis. Its commands and replies were recorded from Redis, each starting from an empty database, and they work as shown in redis-cli.
What the demo shows
- The data. Each restaurant is a hash: a key whose name starts with
restaurant:, holding named fields. Every value in a hash is a string, and Redis finds a hash by its key, not by its contents, until you index it. - Field types.
TEXTfields match words, including other forms of each word, such as plurals.TAGfields match whole values.NUMERICfields match ranges. A query that doesn't fit the field's type finds nothing, and withDIALECT 2it returns an error instead. See Field and type options. - Which keys.
PREFIXdecides which keys an index covers, andFILTERnarrows them down by value. Redis indexes each later write as it happens. SeeFT.CREATE. - Missing and bad values. A value that doesn't fit its field's type keeps Redis from indexing the whole hash, and
FT.INFOcounts the failure.INDEXMISSINGandINDEXEMPTYlet you query for missing and empty values. See Index missing or empty values. - Hash or JSON. An index on JSON documents names JSON paths and gives each one a name with
AS. Queries are the same as for hashes, but a JSON index returns whole documents as JSON, and Redis 8 doesn't supportHIGHLIGHTon it. See Indexing.