$phrase operator matches documents where terms appear in a specific sequence.
Unlike a simple multi-term search that finds documents containing all terms anywhere,
phrase matching requires the terms to appear in the exact order specified.
Simple Form
In its simplest form,$phrase takes a string value and requires the terms to appear adjacent to each other in order:
Slop Parameter
Theslop parameter allows flexibility in phrase matching by permitting other words to appear between your search terms.
The slop value represents the maximum number of position moves allowed to match the phrase.
For example, with slop: 2:
- “wireless headphones” matches (0 moves needed)
- “wireless bluetooth headphones” matches (1 move: “headphones” shifted 1 position)
- “wireless bluetooth overhead headphones” matches (2 moves)
- “wireless bluetooth noise-cancelling headphones” does NOT match (requires 3 moves)
Prefix Parameter
Theprefix parameter allows the last term to match as a prefix.
This is useful for autocomplete scenarios where users might not complete the final word:
slop or prefix, but not both in the same query.
Compatibility
| Field Type | Supported |
|---|---|
| TEXT | Yes |
| U64/I64/F64 | No |
| DATE | No |
| BOOL | No |
Examples
- TypeScript
- Redis CLI