我是 redis 新手...我想问一下 如何在我的 Redis 数据库上使用 FT.SEARCH 来获取 JSON 嵌套对象上的某些字段
"{\"specs\":{\"material\":\"aluminium\",\"weight\":\"10\"},\"brand\":\"Velorim\",\"model\":\"Jigger\",\"price\":270,\"description\":\"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids\xe2\x80\x99 pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.\",\"condition\":\"new\"}"
我尝试用这种方式
FT.SEARCH idx:sepeda "@specs.weight:{10} FT.SEARCH idx:sepeda "@specs.weight:10
但出现错误
"Syntax error at offset 7 near weight"
我必须做什么
您需要创建一个索引。请参阅文档
例如,对于数字权重,
127.0.0.1:6379> FT.CREATE idx ON JSON SCHEMA '$.specs.weight' as weight NUMERIC
带有诸如
之类的文件127.0.0.1:6379> JSON.SET doc:1 $ "{\"specs\":{\"material\":\"aluminium\",\"weight\":10},\"brand\":\"Velorim\",\"model\":\"Jigger\",\"price\":270,\"description\":\"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids\xe2\x80\x99 pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.\",\"condition\":\"new\"}"
可以搜索具体权重,例如10到15(含)范围内
127.0.0.1:6379> FT.SEARCH idx '@weight:[10 15]' NOCONTENT
1) (integer) 1
2) "doc:1"