Redis Enterprise中如何用JSON.GET查询包含Winter的season数据
Redis JSON 查询 season 包含"Winter"的条目
要查询warehouse:1中inventory数组里season包含"Winter"的元素,可以使用带过滤条件的JSON.GET命令:
JSON.GET warehouse:1 '$..inventory[?(@.season[] == "Winter")]'
命令解析
$..inventory:递归定位到文档中的inventory数组[?(@.season[] == "Winter")]:过滤数组元素,@代表当前数组元素,@.season[]遍历该元素的season数组所有值,只要其中有一个等于"Winter",该元素就会被匹配返回
如果只需要返回特定字段(比如商品ID和描述),可以调整路径来指定返回结构:
JSON.GET warehouse:1 '$..inventory[?(@.season[] == "Winter")].{"id":@.id, "description":@.description}'
内容的提问来源于stack exchange,提问作者JShao
相关产品推荐
相关产品推荐

