Every search index requires a schema that defines the structure of searchable documents. The schema allows for type-safety and allows us to optimize your data for very fast queries. We provide a schema builder utility calledDocumentation Index
Fetch the complete documentation index at: https://upstash-cloud-4245.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
s that makes it easy to define a schema.
Field Type Reference
| SDK Method | Redis CLI Type | Description | Supports FAST | Range Operators | Text Operators |
|---|---|---|---|---|---|
s.string() | TEXT | Full-text searchable field with tokenization and stemming | No | No | $smart, $phrase, $fuzzy, $regex |
s.keyword() | KEYWORD | Exact-match string (no tokenization) | Yes | Yes ($gt, $gte, $lt, $lte) | No |
s.number() | F64 (default), U64, I64 | Numeric field | Yes | Yes | No |
s.date() | DATE | Date/time field | Yes | Yes | No |
s.boolean() | BOOL | Boolean field | Yes | No | No |
s.facet() | FACET | Hierarchical path-based field | No | No | No (only $eq, $in) |
In the TypeScript SDK,
s.number() defaults to F64. You can specify s.number("U64") or
s.number("I64") for unsigned or signed 64-bit integers. F64 fields are FAST by default.FAST Fields
TheFAST flag creates a columnar store for a field, enabling:
- Sorting with
ORDERBYin queries - Score functions with
SCOREFUNC FIELDVALUE - Metric aggregations (
$avg,$sum,$min,$max,$count, etc.)
F64), boolean, and date fields are FAST by default. You can
disable it with .fast(false). In Redis CLI, you must explicitly add the FAST keyword after the
field type.
ORDERBY, SCOREFUNC, or metric aggregations on a non-FAST field, you will get an error.
Basic Usage
The schema builder provides methods for each field type:noTokenize() and noStem() are used for in the section below.
Nested Objects
The schema builder supports nested object structures:Where to use the Schema
We need the schema when creating or querying an index:Tokenization & Stemming
When you store text in a search index, it goes through two transformations: Tokenization and Stemming. By default, text fields are both tokenized and stemmed. Understanding these helps you configure fields correctly.Tokenization
Tokenization splits text into individual searchable words (tokens) by breaking on spaces and punctuation.| Original Text | Tokens |
|---|---|
"hello world" | ["hello", "world"] |
"user@example.com" | ["user", "example", "com"] |
"SKU-12345-BLK" | ["SKU", "12345", "BLK"] |
.noTokenize():
- Email addresses (
user@example.com) - URLs (
https://example.com/page) - Product codes and SKUs (
SKU-12345-BLK) - UUIDs (
550e8400-e29b-41d4-a716-446655440000) - Category slugs (
electronics/phones/android)
Stemming
Stemming reduces words to their root form so different variations match the same search.| Word | Stemmed Form |
|---|---|
"running", "runs", "runner" | "run" |
"studies", "studying", "studied" | "studi" |
"experiments", "experimenting" | "experi" |
.noStem():
- Brand names (
Nikeshouldn’t matchNik) - Proper nouns and names (
Johnsonshouldn’t becomeJohn) - Technical terms (
Reactshouldn’t matchReac) - When using regex patterns (stemmed text won’t match your expected patterns)
Keyword Fields
TheKEYWORD field type is for exact-match strings. Unlike TEXT fields, keywords are not tokenized or stemmed — the entire value is treated as a single token.
KEYWORD fields support numeric query operators ($eq, $in, $gt, $gte, $lt, $lte), which are not available on TEXT fields.
- TypeScript
- Python
- Redis CLI
- When you need range operators (
$gt,$gte,$lt,$lte) on string values - When the entire string should be treated as a single unit (no word splitting)
- For tags, labels, status codes, or any string that should match exactly
Facet Fields
TheFACET field type is for hierarchical path-based faceted search. Values must be /-delimited paths starting with /.
FACET fields only support $eq and $in operators.
They are primarily used with the $facet aggregation
to build category trees and faceted navigation.
- TypeScript
- Python
- Redis CLI
- TypeScript
- Python
- Redis CLI
Aliased Fields
Aliased fields allow you to index the same document field multiple times with different settings, or to create shorter names for complex nested paths. Use theFROM keyword to specify which document field the alias points to.
- TypeScript
- Python
- Redis CLI
- Same field with different settings: Index a text field both with and without stemming. Use the stemmed version for general searches and the non-stemmed version for exact matching or regex queries.
- Shorter query paths: Create concise aliases for deeply nested fields like
metadata.author.displayNameto simplify queries.
When using aliased fields:
- Use the alias name in queries and highlighting (e.g.,
descriptionExact,authorName) - Use the actual field name when selecting fields to return (e.g.,
description,metadata.author.displayName)
Non-Indexed Fields
Documents don’t need to match the schema exactly:- Extra fields: Fields in your document that aren’t defined in the schema are simply ignored. They won’t be indexed or searchable.
- Missing fields: If a document is missing a field defined in the schema, that document won’t appear in search results that filter on the missing field.
Schema Examples
E-commerce product schema- TypeScript
- Python
- Redis CLI
- TypeScript
- Python
- Redis CLI