Skip to main content

Documentation Index

Fetch the complete documentation index at: https://upstash.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

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 } },
});

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" },
});

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" },
});

Deletes

Deleting a matching key removes the document from the index.
await redis.del("product:1");
await products.waitIndexing();

Expiration

When a matching key expires, Upstash Redis Search removes the expired document from the index.
await redis.expire("product:flash-sale", 3600);

Eviction

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.