- TypeScript
- Redis CLI
Smart Matching for Text Fields
When you provide a value directly to a text field (without explicit operators), we automatically apply smart matching. Under the hood, it works like this:- Single-word values: Performs a term search, matching the word against tokens in the field.
- Multi-word values: Combines phrase matching, term matching, and fuzzy matching with different boost weights to rank exact phrases highest while still finding partial matches.
- Double-quoted phrases: Forces exact phrase matching (e.g.,
"\"noise cancelling\""matches only those words adjacent and in order).
$phrase,
$fuzzy, or $contains.
Query Options
1. Pagination with Limit and Offset
Limit controls how many results to return. Offset controls how many results to skip. Together, they provide a way to paginate results.- TypeScript
- Redis CLI
2. Sorting Results
Normally, search results are sorted in descending order of query relevance. It is possible to override this, and sort the results by a certain field in ascending or descending order. Only fields defined as.fast() in the schema can be used as the sort field (enabled by default).
When using orderBy, the score in results reflects the sort field’s value rather than relevance.
- TypeScript
- Redis CLI
3. Controlling Output
By default, search results include document key, relevance score, and the contents of the document (including the non-indexed fields). For JSON and string indexes, that means the stored JSON objects as whole. For hash indexes, it means all fields and values.- TypeScript
- Redis CLI
- TypeScript
- Redis CLI
When using aliased fields,
use the actual document field name (not the alias) when selecting fields to return.
This is because aliasing happens at the index level and does not modify the underlying documents.
4. Highlighting
Highlighting allows you to see why a document matched the query by marking the matching portions of the document’s fields. By default,<em> and </em> are used as the highlight tags.
- TypeScript
- Redis CLI
When using aliased fields,
use the alias name (not the actual document field name) when specifying fields to highlight.
The highlighting feature works with indexed field names, which are the aliases.