Creating an Index
TheSEARCH.CREATE command creates a new search index that automatically tracks keys matching specified prefixes.
An index is identified by its name, which must be a unique key in Redis.
Each index works only with a specified key type (JSON, hash, or string)
and tracks changes to keys matching the prefixes defined during index creation.
- TypeScript
- Redis CLI
- TypeScript
- Redis CLI
- Prefixes must not contain duplicates.
- No prefix should cover another prefix (e.g.,
user:anduser:admin:are not allowed together). - Multiple distinct prefixes are allowed (e.g.,
article:andblog:are valid together).
- TypeScript
- Redis CLI
SKIPINITIALSCAN to defer indexing, which is useful for large datasets where you want to start fresh or handle
existing data differently.
- TypeScript
- Redis CLI
english.
Currently, the following languages are supported:
englisharabicdanishdutchfinnishfrenchgermangreekhungarianitaliannorwegianportugueseromanianrussianspanishswedishtamilturkish
- TypeScript
- Redis CLI
EXISTOK option.
- TypeScript
- Redis CLI
Getting an Index Client
Theredis.search.index() method creates a client for an existing index without making a Redis call. This is useful when you want to query or manage an index that already exists, without the overhead of creating it.
- TypeScript
redis.search.createIndex() which:
- Creates a new index if it doesn’t exist
- Makes a Redis call to create the index
- Returns an error if the index already exists (unless
EXISTOKis used)
redis.search.index() when:
- The index already exists
- You want to avoid unnecessary Redis calls
- You’re querying or managing an existing index
redis.search.createIndex() when:
- You need to create a new index
- You’re setting up your application for the first time
Describing an Index
TheSEARCH.DESCRIBE command returns detailed information about an index.
- TypeScript
- Redis CLI
| Field | Description |
|---|---|
name | Index name |
type | Data type (STRING, HASH, or JSON) |
prefixes | List of tracked key prefixes |
language | Stemming language |
schema | Field definitions with types and options |
Dropping an Index
TheSEARCH.DROP command removes an index and stops tracking associated keys.
- TypeScript
- Redis CLI
Waiting for Indexing
For adequate performance, index updates are batched and committed periodically. This means recent writes may not immediately appear in search results. UseSEARCH.WAITINDEXING when you need to ensure queries reflect recent changes.
The SEARCH.WAITINDEXING command blocks until all pending index updates are processed and visible to queries.
We recommend not to call this command each time you perform a write operation on the index. For optimal indexing and
query performance, batch updates are necessary.
- TypeScript
- Redis CLI