SEARCH.QUERY to search for documents matching a JSON filter.
The filter is a JSON object naming index fields and the values to match, so '{"name": "headphones", "inStock": true}' combines conditions with an implicit AND. Text fields are matched with the analysis configured in the schema while other types are matched exactly, and operators such as $fuzzy, $prefix, $range, $or, and $mustNot cover the cases where plain field matching is not enough. Querying an index that does not exist returns null.
Results come back ordered by relevance score by default. ORDERBY sorts by a FAST field instead, LIMIT and OFFSET page through the matches, SELECT and NOCONTENT cut the payload down to the fields you need, HIGHLIGHT wraps the matched terms in tags for display, and SCOREFUNC blends numeric fields such as popularity or recency into the relevance score.
A KEYWORD or TEXT field whose value is a JSON array is indexed element by element, so a document matches when any element matches the condition. HIGHLIGHT preserves that shape: the field comes back as the same array with the matching elements marked up, and elements that did not match, including non-string ones, unchanged. The stored document is never modified.
See Querying and filtering for the full filter syntax and worked examples, and SEARCH.COUNT when you only need the number of matches.
Syntax
Arguments
See Querying and filtering for the JSON filter operators and detailed query examples.
Response
Returns an array of[key, score, content] results, or null if the index does not exist:
keyis the Redis key of the matching document.scoreis the floating-point relevance score.contentis an array of field-value pairs. JSON indexes return[["$", "<json_string>"]]; hash indexes return[["field", "value"], ...].
NOCONTENT is used, each result is [key, score]. When SELECT is used, only fields that exist in the document appear in the content. For an index created with ON STREAM, key is the entry ID of the matching stream entry.
A highlighted multi-valued field keeps its array form in the reply. Highlighting a on a document whose a is ["hello world", "foo & bar", 7] returns ["<em>hello</em> world","foo & bar",7].
Examples
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs
curl
curl