英文:
Enterprise Redis JSON.GET Syntax for JSONARRAY contains
问题
如何在 JSON.GET warehouse:1 中查询包含 "Winter" 的 "season" 内容?
英文:
I'am looking what functionalities that Redis Enterprise can offer, and came up with following questions.
Content in JSON using JSON.Set
JSON.SET warehouse:1 $ '{
"city": "Boston",
"location": "42.361145, -71.057083",
"inventory": [
{
"id": 15970,
"gender": "Men",
"season":["Fall", "Winter"],
"description": "Turtle Check Men Navy Blue Shirt",
"price": 34.95
},
{
"id": 59263,
"gender": "Women",
"season": ["Fall", "Winter", "Spring", "Summer"],
"description": "Titan Women Silver Watch",
"price": 129.99
},
{
"id": 46885,
"gender": "Boys",
"season": ["Fall"],
"description": "Ben 10 Boys Navy Blue Slippers",
"price": 45.99
}
]
}'
How to write JSON.GET warehouse:1 for "season" contains "Winter"
答案1
得分: 0
你正在寻找的是JSONPath中的“包含”操作。目前,我认为这是不可能的。这不是Redis Enterprise或Redis Stack的限制,而是JSONPath本身的限制。
我进行了一些搜索,发现一些关于JSONPath提出的用于执行此操作的语法片段。然而,目前还没有实现任何内容。
也许有一种巧妙的方法可以绕过这个问题,但我想不出来。我建议您查看Redis的JSONPath文档,特别关注过滤示例,以及尝试使用在线评估器来尝试JSONPath的各种功能。
英文:
What you are looking for is a "contains" operation for JSONPath. At the moment, I don't believe this is possible. This isn't a limitation with Redis Enterprise or Redis Stack, this is a limitation of JSONPath itself.
I did some googling and found some bits and bobs with proposed syntax for JSONPath to do this. However, nothing implemented yet.
There might be a clever hack to get around this but I couldn't think of one. I would suggest that you check out the JSONPath docs for Redis, looking specifically at the filtering examples, and that you play around with what you can do with JSONPath with an online evaluator.
答案2
得分: 0
-
如果您知道要查看哪个JSON文档,可以使用JSONPath过滤器,正如Guy Royse建议的那样,例如,要获取具有
Winter
季节的物品的id:JSON.GET warehouse:1 '$.inventory[?(@.season[?(@=="Winter")])].id';
-
如果您不知道要查看哪个JSON文档,可以使用RediSearch,正如Simon Prickett建议的那样,例如:
FT.CREATE idx:inventory ON JSON SCHEMA '$.inventory[*].season[*]' AS season TAG
然后搜索文档:
FT.SEARCH idx:inventory @season:{Winter}
或者还可以检索相关的id:
FT.SEARCH idx:inventory @season:{Winter} RETURN 1 '$.inventory[?(@.season[?(@=="Winter")])].id';
英文:
-
If you know which JSON document to look into, JSONPath filters can be used, as suggested by Guy Royse,
For example, to get the id of items withWinter
in season:JSON.GET warehouse:1 '$.inventory[?(@.season[?(@=="Winter")])].id'
-
If you do not know which JSON document to look into, RediSearch can be used, as suggested by Simon Prickett,
For example:FT.CREATE idx:inventory ON JSON SCHEMA '$.inventory[*].season[*]' AS season TAG
And then search for documents
FT.SEARCH idx:inventory @season:{Winter}
Or also retrieve the relevant id
FT.SEARCH idx:inventory @season:{Winter} RETURN 1 '$.inventory[?(@.season[?(@=="Winter")])].id'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论