Available Operators
How Boolean Operators Work Together
Boolean operators can be combined in a single query to express complex logic. The operators work together as follows:$mustdefines the required conditions. Documents must match ALL of these.$shouldadds optional conditions:- When used alone: documents must match at least one condition
- When combined with
$must: conditions become optional score boosters
$mustNotfilters out unwanted documents from the result set.
Combining Operators
Here’s an example that uses all three operators together:- TypeScript
- Redis CLI
- Requires documents to be in the “electronics” category AND in stock
- Boosts documents that mention “wireless” or “bluetooth” (but doesn’t require them)
- Excludes any documents containing “budget” in the description
Nesting Boolean Operators
Boolean operators can be nested to create more complex logic:- TypeScript
- Redis CLI