我有一个带有map作为数据类型的bin,并在MAPKEYS上创建了一个辅助。现在我想在MAPKEYS索引上运行带过滤器的udf。它给出了错误AEROSPIKE_ERR_INDEX_NOT_FOUND。
这是我的aql查询:
AQL>在MAPKEYS中的test.user上聚合test.check_password('hii'),其中pids ='test2'
错误:(201)AEROSPIKE_ERR_INDEX_NOT_FOUND
而普通查询的工作原理为
AQL>从MAPKEYS中的test.user选择*,其中pids ='test2'
返回一些数据
为测试而插入的样本数据,在理想情况下,它将是一个字符串到对象的映射
答案 0 :(得分:2)
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k1', MAP('{"test1": "t1", "test2": "t2", "test3":"t3", "test4":"t4", "test5":"t5"}'), "t2bin", "t1bin")
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k2', MAP('{"test1": "t1", "test3":"t3", "test4":"t4", "test5":"t5"}'), "t2b", "t1b")
aql> INSERT INTO test.user (PK, pids, test2, test1) VALUES ('k3', MAP('{"test1": "t1", "test2":"t22", "test4":"t4", "test5":"t5"}'), "t2b", "t1b")
aql> CREATE MAPKEYS INDEX pidIndex ON test.user (pids) STRING
OK, 1 index added.
aql> select * from test.user in MAPKEYS where pids="test2"
+--------------------------------------------------------------------------------+---------+---------+
| pids | test2 | test1 |
+--------------------------------------------------------------------------------+---------+---------+
| MAP('{"test2":"t22", "test4":"t4", "test5":"t5", "test1":"t1"}') | "t2b" | "t1b" |
| MAP('{"test2":"t2", "test3":"t3", "test4":"t4", "test5":"t5", "test1":"t1"}') | "t2bin" | "t1bin" |
+--------------------------------------------------------------------------------+---------+---------+
我以你的格式插入了三条记录,其中一条记录在地图中没有test2键(k2)。然后我在MAPKEY上创建了二级索引并运行查询,给了我想要的结果。
AGGREGATE用于在此结果记录集上运行用户定义函数流。您要运行的UDF代码是什么?
(AGGREGATE test.check_password(“hii”)....暗示你有一个test.lua文件,它有一个带字符串参数的check_password()函数。)
您必须首先在MAP密钥上创建辅助索引。其报告索引未找到。要检查您是否拥有索引,您可以执行以下操作:
aql> show indexes
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
| ns | bin | indextype | set | state | indexname | path | sync_state | type |
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
| "test" | "pids" | "MAPKEYS" | "user" | "RW" | "pidIndex" | "pids" | "synced" | "STRING" |
+--------+--------+-----------+--------+-------+------------+--------+------------+----------+
1 row in set (0.000 secs)
OK