Back to results for “JSON”
Redis › RedisJSON

How can you combine RedisJSON with RedisSearch to enable searching across specific fields within stored JSON documents?

Intermediate

Answer

You create a search index using RedisSearch that specifically defines certain fields within your JSON documents as searchable, and RedisSearch then automatically indexes those fields as JSON documents are added or updated, letting you run rich search queries directly against structured data stored using RedisJSON.
FT.CREATE product_idx ON JSON PREFIX 1 product: SCHEMA $.name AS name TEXT $.price AS price NUMERIC
FT.SEARCH product_idx '@name:laptop'
Real-world example An e-commerce platform combines RedisJSON for storing detailed product documents with RedisSearch for building a fast, flexible product search feature across specific fields like name and price within those documents.

Common follow-ups: Does every field in a JSON document need to be indexed, or can you choose specific ones?;What happens to the search index when a JSON document is updated?