Upstash Documentation

SEARCH.QUERY

Search documents with a JSON filter.
3 min read

Use 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.

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#

ArgumentDescriptionDefault
LIMITMaximum number of results to return. Must be between 1 and 1000.10
OFFSETNumber of results to skip for pagination. Must be between 0 and 10,000.0
ORDERBYSort by a FAST field. The direction defaults to DESC when omitted.Relevance score, descending
SELECTReturn only the specified number of document fields. When the schema uses FROM, specify the source document field rather than its index alias.All fields
NOCONTENTReturn keys and scores without document content.Disabled
HIGHLIGHTWrap matching terms in tags. The default tags are <em> and </em>.Disabled
SCOREFUNCAdjust relevance scores using one or more FAST numeric fields. FACTOR defaults to 1, MISSING to 0, MODIFIER to NONE, SCOREMODE to SUM, and COMBINEMODE to SUM.Disabled
Warning

NOCONTENT cannot be combined with SELECT or HIGHLIGHT. SCOREFUNC cannot be combined with ORDERBY. Inside MULTI or EVAL, the command requires NOCONTENT.

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:

  • key is the Redis key of the matching document.
  • score is the floating-point relevance score.
  • content is an array of field-value pairs. JSON indexes return [["$", "<json_string>"]]; hash indexes return [["field", "value"], ...].

When NOCONTENT is used, each result is [key, score]. When SELECT is used, only fields that exist in the document appear in the content.

Examples#

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
curl