Schema Builder Utility
The TypeScript SDK provides a convenient schema builder utilitys that makes it easy to define schemas with type safety and better developer experience.
Importing the Schema Builder
Basic Usage
The schema builder provides methods for each field type:Field Options
The schema builder supports chaining field options:Nested Objects
The schema builder supports nested object structures:Using Schema with Index Creation
Schema Builder vs. Plain Objects
You can define schemas using either the schema builder or plain objects:- Schema Builder (Recommended)
- Plain Object
- Better type safety
- Autocomplete support
- More readable and maintainable code
- Easier refactoring
Field Types
| Type | Description | Example Values |
|---|---|---|
TEXT | Full-text searchable string | "hello world", "The quick brown fox" |
U64 | Unsigned 64-bit integer | 0, 42, 18446744073709551615 |
I64 | Signed 64-bit integer | -100, 0, 9223372036854775807 |
F64 | 64-bit floating point | 3.14, -0.001, 1e10 |
BOOL | Boolean | true, false |
DATE | RFC 3339 timestamp | "2024-01-15T09:30:00Z", "1985-04-12T23:20:50.52Z" |
Field Options
Options modify field behavior and enable additional features.Text Field Options
By default, text fields are tokenized and stemmed. Stemming reduces words to their root form, enabling searches for “running” to match “run,” “runs,” and “runner.” This is controlled per-field withNOSTEM and globally with the LANGUAGE option.
| Language | Example Stemming |
|---|---|
english | ”running” → “run”, “studies” → “studi” |
turkish | ”koşuyorum” → “koş” |
| Option | Description | Use Case |
|---|---|---|
NOSTEM | Disable word stemming | Names, proper nouns, technical terms |
NOTOKENIZE | Treat entire value as single token | URLs, UUIDs, email addresses, category codes |
$regex, be aware of stemming behavior:
- TypeScript
- Redis CLI
NOSTEM on fields where you need exact regex matching
Numeric, Boolean, and Date Field Options
| Option | Description | Use Case |
|---|---|---|
FAST | Enable fast field storage | Sorting, fast range queries, field retrieval |
Nested Fields
You can define fields at arbitrary nesting levels using the. character as a separator.
Non-Indexed Fields
Although the schema definition is strict, documents do not have to match with the schema exactly. There might be missing or extra fields in the documents. In that case, extra fields are not part of the index, and missing fields are not indexed for that document at all. So, documents with missing fields won’t be part of the result set, where there are required matches for the missing fields.Schema Examples
E-commerce product schema- TypeScript
- Redis CLI
- TypeScript
- Redis CLI