Document Updates
Documents in a search index are regular Redis keys.
When a key matches an index prefix, it is indexed automatically. When the key changes, the index is updated automatically.
There is no separate update command for search. Use regular Redis write commands to change your data.
Any command that modifies a matching key updates the index. For example, this includes commands such as:
- JSON commands such as
JSON.SET,JSON.MERGE, ... - Hash commands such as
HSET,HINCRBY, ... - String commands such as
SET,SETEX, ... - Generic commands such as
DEL,EXPIRE,PEXPIRE, ...
This is not an exhaustive list. The rule is that if the command changes a key tracked by the index, the index is updated.
Index updates are batched for performance, so recent writes may not immediately appear in search results.
Use SEARCH.WAITINDEXING when you need to ensure queries reflect recent changes.
JSON Documents
For JSON indexes, any JSON command that modifies a matching key updates the indexed document.
import { Redis } from "@upstash/redis";const redis = Redis.fromEnv();const products = redis.search.index({ name: "products" });await redis.json.set("product:1", "$.price", 79.99);await products.waitIndexing();const discounted = await products.query({ filter: { price: { $lt: 90 } },});from upstash_redis import Redisredis = Redis.from_env()products = redis.search.index(name="products")redis.json.set("product:1", "$.price", 79.99)products.wait_indexing()discounted = products.query(filter={"price": {"$lt": 90}})JSON.SET product:1 $.price 79.99SEARCH.WAITINDEXING productsSEARCH.QUERY products '{"price":{"$lt":90}}'Hash Documents
For hash indexes, any hash command that modifies a matching key updates the indexed document.
const articles = redis.search.index({ name: "articles" });await redis.hset("article:1", { status: "published", views: 125,});await articles.waitIndexing();const published = await articles.query({ filter: { status: "published" },});articles = redis.search.index(name="articles")redis.hset("article:1", values={ "status": "published", "views": 125,})articles.wait_indexing()published = articles.query(filter={"status": "published"})HSET article:1 status published views 125SEARCH.WAITINDEXING articlesSEARCH.QUERY articles '{"status":"published"}'String Documents
For string indexes, indexed keys must contain valid JSON strings. Any command that replaces or modifies the matching string key updates the indexed document.
const notes = redis.search.index({ name: "notes" });await redis.set("note:1", { title: "Release checklist", status: "done",});await notes.waitIndexing();const done = await notes.query({ filter: { status: "done" },});notes = redis.search.index(name="notes")redis.set("note:1", '{"title":"Release checklist","status":"done"}')notes.wait_indexing()done = notes.query(filter={"status": "done"})SET note:1 '{"title":"Release checklist","status":"done"}'SEARCH.WAITINDEXING notesSEARCH.QUERY notes '{"status":"done"}'Deletes
Deleting a matching key removes the document from the index.
await redis.del("product:1");await products.waitIndexing();redis.delete("product:1")products.wait_indexing()DEL product:1SEARCH.WAITINDEXING productsExpiration
When a matching key expires, Upstash Redis Search removes the expired document from the index.
await redis.expire("product:flash-sale", 3600);redis.expire("product:flash-sale", 3600)EXPIRE product:flash-sale 3600Eviction
When an indexed key is evicted, Upstash Redis Search removes the document from the index. Once the Redis key is gone, it no longer appears in search results.