0

我有一个带有 map 作为数据类型的 bin,并在 MAPKEYS 上创建了一个辅助文件夹。现在我想在 MAPKEYS 索引上运行带有过滤器的 udf。它给出了错误AEROSPIKE_ERR_INDEX_NOT_FOUND。

这是我的 aql 查询:
aql> aggregate test.check_password('hii') on test.user in MAPKEYS where pids = 'test2' Error: (201) AEROSPIKE_ERR_INDEX_NOT_FOUND

而正常查询工作
aql> select * from test.user in MAPKEYS where pids = 'test2'
返回一些数据

插入用于测试的示例数据,在理想情况下,它将是 String 到 Object 的 Map

在此处输入图像描述

4

1 回答 1

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" |
+--------------------------------------------------------------------------------+---------+---------+

我以您的格式插入了三条记录,一条在其映射(k2)中没有 test2 键。然后我在 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
于 2017-08-20T21:46:39.243 回答