我将RedisJSON和RediSearch模块一起用于对JSON数据执行搜索查询。对于每个JSON对象,我需要索引数组字段中的所有字符串元素,以便能够通过查询数组中的一个字符串(即通过搜索图书JSON中的字符串数组中包含的作者之一获得一些图书数据)来获得这个对象。然而,目前看来是不可能。有什么解决办法吗?还是我被困住了?
发布于 2021-12-28 11:31:49
您需要尝试最新版本的RediSearch+RedisJSON。
来自你指的是github问题的示例用于RedisJSON 2.0.5和RediSearch 2.2.5
127.0.0.1:6379> ft.create index on json schema $.names[0:].first as first tag
OK
127.0.0.1:6379> json.set pserson:1 $ '{"names":[{"first": "fname1","last": "lname1"},{"first": "fname2","last": "lname2"},{"first": "fname3", "last": "lname3"}]}'
OK
127.0.0.1:6379> ft.search index @first:{fname1}
1) (integer) 1
2) "pserson:1"
3) 1) "$"
2) "{\"names\":[{\"first\":\"fname1\",\"last\":\"lname1\"},{\"first\":\"fname2\",\"last\":\"lname2\"},{\"first\":\"fname3\",\"last\":\"lname3\"}]}"
127.0.0.1:6379> ft.search index @first:{fname2}
1) (integer) 1
2) "pserson:1"
3) 1) "$"
2) "{\"names\":[{\"first\":\"fname1\",\"last\":\"lname1\"},{\"first\":\"fname2\",\"last\":\"lname2\"},{\"first\":\"fname3\",\"last\":\"lname3\"}]}"
下面是特定的redis-cli info modules
module:name=ReJSON,ver=20005,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]
module:name=search,ver=20205,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
https://stackoverflow.com/questions/70509976
复制