Upstash Documentation

SEARCH.CREATE

Create a search index.
4 min read

Use SEARCH.CREATE to create a search index over JSON, hash, or string values, or over a stream.

ON names the type of key to index and PREFIX the key prefixes to watch, so the index covers exactly the keys that match both, including keys written after it was created. The SCHEMA then declares which fields are searchable and how: TEXT fields are analyzed for full-text search, with NOSTEM and NOTOKENIZE to turn parts of that off, numeric, boolean, and date fields are matched exactly and can be marked FAST to make them usable for sorting and scoring, and KEYWORD and FACET fields are kept whole for exact matching and faceting. FROM maps a schema field to a differently named field in the document.

ON STREAM indexes a single stream instead of a set of keys, so it takes the stream key in place of PREFIX. Each entry added with XADD becomes a document whose fields are the entry's fields and whose ID is the entry ID, which is what makes a stream searchable by content rather than only by ID range. Entries removed from the stream leave the index as well.

A KEYWORD or TEXT field whose value is a JSON array of values is indexed as several values rather than as one string. A document matches when any element matches, so a tags field or a list of descriptions needs no separate key per value. HIGHLIGHT follows the same shape: the reply keeps the array, with the matching elements marked up and the others, including any non-string elements, left as they are.

Creating an index starts an initial scan of the matching keys, which SKIPINITIALSCAN skips when you only want to index data written from now on; SEARCH.REINDEX can run that scan later. EXISTSOK makes the command succeed instead of failing when the index already exists.

See Index Management for a feature-level guide to creating indexes and Schema Definition for field types and schema design.

Note

Upstash Redis Search uses SEARCH.* commands. They are separate from and incompatible with the FT.* commands in the open-source RediSearch module.

Syntax#

Arguments#

ArgumentDescription
ONType of Redis value to index: JSON, HASH, STRING, or STREAM. A STRING value must contain a JSON object.
PREFIXOne or more key prefixes. Prefixes in the same index cannot be duplicates or overlap one another. Not allowed with ON STREAM.
<stream-key>Key of the stream to index. Required with ON STREAM, and given in place of PREFIX.
LANGUAGEStemming language for TEXT fields. Defaults to english. Supported values are arabic, danish, dutch, english, finnish, french, german, greek, hungarian, italian, norwegian, portuguese, romanian, russian, spanish, swedish, tamil, and turkish.
SKIPINITIALSCANCreate the index without scanning existing keys. Later writes are still indexed; use SEARCH.REINDEX to add the current matching data.
EXISTSOKReturn 0 when an index with the same data type, prefixes, and schema already exists. A configuration mismatch returns an error.
SCHEMAOne or more field definitions. SCHEMA must be the final top-level clause.

Schema field options#

OptionValid field typesDescription
FASTU64, I64, F64, BOOL, DATEStore the field for operations such as sorting and aggregations. Score functions accept FAST fields of type U64, I64, or F64.
NOSTEMTEXTIndex text without stemming words to their roots.
NOTOKENIZETEXTIndex the entire value as one token.
FROM <source_field>All field typesRead the value from a different document field or nested dot path while exposing it under <field> in the index.

KEYWORD and TEXT fields accept multiple values: a field whose value is a JSON array is indexed element by element, and a document matches when any element matches.

Response#

Returns 1 when the index is created. With EXISTSOK, returns 0 if the existing index has the same data type, prefixes, and schema. Returns an error for a different configuration or when <name> is already used by a non-index Redis key.

Examples#

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs
curl