Redis Cloud automatically indexes JSON and hash documents in databases where Redis Search is enabled. Beginning with Redis Search 2.0 (included in Redis Cloud and Redis Stack), indexing no longer relies on the legacy FT.ADD workflow. Instead, Redis Cloud continuously monitors keyspace activity and indexes documents whose keys match the prefixes defined in your index schema. This article describes how indexing works in Redis Cloud, outlines the steps to create an index, and provides guidance for validating indexed results and troubleshooting common issues.
Prerequisites
Active Redis Cloud subscription with Redis Search enabled.
Access to the Redis Cloud Console
Redis Stack client library or redis-cli (for JSON and Search support).
How Indexing Works
In Redis Cloud, all databases with Redis Search automatically track eligible keys.
When you insert, update, or delete JSON or hash documents, Redis Cloud synchronously updates the index.
Key points:
FT.ADDis deprecated and shouldn't be used with Redis Search 2.x.New or modified documents are indexed immediately.
Existing data is indexed asynchronously after an index is created.
Step-by-Step Setup
1. Create an Index
JSON Example
FT.CREATE idx:users ON JSON PREFIX 1 user: SCHEMA $.name AS name TEXT $.city AS city TAG $.age AS age NUMERIC
Hash Example
FT.CREATE hash-idx:users ON HASH PREFIX 1 huser: SCHEMA name TEXT city TAG age NUMERIC
2. Add Documents
JSON Documents
JSON.SET user:1 $ '{"name":"Alice","city":"London","age":30}'
JSON.SET user:2 $ '{"name":"Bob","city":"Paris","age":25}'Hash Documents
HSET huser:1 name "Alice" city "London" age 30 HSET huser:2 name "Bob" city "Paris" age 25
3. Query the Index
FT.SEARCH idx:users "@city:{London}"
FT.SEARCH idx:users "@age:[25 35]"Troubleshooting
Issue |
Resolution |
|---|---|
Documents not appearing in results |
Ensure key prefix matches the index schema and that Search and Query are enabled. |
Index not updating after changes |
Wait a few seconds; asynchronous reindexing may still be in progress. |
Schema mismatch |
Check that JSONPath expressions match your document structure. |
Using deprecated commands |
Remove FT.ADD as updating or setting keys (e.g., HSET or JSON.SET) will update the index |
0 comments
Please sign in to leave a comment.