FT.CREATE

Since 1.1.0Search

Syntax

FT.CREATE index ON HASH|JSON PREFIX n prefix [...] [STOPWORDS n word …] SCHEMA field [AS name] type [options ...]
  • Flags: write
  • ACL categories: @search, @slow, @write
  • Arity: -1

Creates a search index over the hashes, or JSON documents, whose keys start with the given prefixes. Existing keys are indexed at once, and keys written later as they are written.

Options

OptionEffect
ON HASH | JSONIndex hashes, by field name, or JSON documents, by JSONPath. Hashes with field expiry are indexed too.
PREFIX n prefix ...The key prefixes to index.
STOPWORDS n word ...Words left out of TEXT fields.
SCHEMA field [AS name] type [options] ...The fields: TEXT, TAG, NUMERIC or VECTOR. AS gives a JSONPath, or a hash field, the name queries use. SORTABLE lets SORTBY use a field.

See Search queries for what each field type matches, and its VECTOR options.

Reply

  • OK.
  • Index already exists.

Examples

> FT.CREATE products ON HASH PREFIX 1 product: SCHEMA name TEXT category TAG price NUMERIC SORTABLE embedding VECTOR HNSW 6 TYPE FLOAT32 DIM 3 DISTANCE_METRIC COSINE
OK
> FT.CREATE books ON JSON PREFIX 1 book: SCHEMA $.title AS title TEXT $.year AS year NUMERIC $.tags[*] AS tags TAG
OK