我正在尝试将地图存储在 aerospike 中并根据地图的键获取数据。
首先,我在存储地图的垃圾箱上创建了一个索引
aql> create mapkeys index status on test.myset (state) String
aql> show indexes
+--------+---------+-----------+---------+-------+-----------+---------+------------+----------+
| ns | bin | indextype | set | state | indexname | path | sync_state | type |
+--------+---------+-----------+---------+-------+-----------+---------+------------+----------+
| "test" | "state" | "MAPKEYS" | "myset" | "RW" | "status" | "state" | "synced" | "STRING" |
+--------+---------+-----------+---------+-------+-----------+---------+------------+----------+
1 row in set (0.000 secs)
OK
然后我用java客户端来存储地图
AerospikeClient client = new AerospikeClient("127.0.0.1",3000);
WritePolicy writePolicy = new WritePolicy();
writePolicy.timeout=500;
for(int i = 1;i<10;i++){
Key key = new Key("test","myset",""+i);
client.delete(writePolicy, key);
HashMap<String,String> map = new HashMap<String,String>();
map.put("key1", "string1");
map.put("key2", "string2");
map.put("key3", "string3");
Bin bin = new Bin("state", map);
client.put(writePolicy, key, bin);
}
我通过apl检查了数据,数据清晰存在。
aql> select * from test.myset
+--------------------------------------------------------+
| state |
+--------------------------------------------------------+
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
| {"key1":"string1", "key2":"string2", "key3":"string3"} |
+--------------------------------------------------------+
10 rows in set (0.019 secs)
现在,当我尝试根据创建的索引进行查询时,它给出
aql> select * from test.myset where status = 'key1'
0 rows in set (0.000 secs)
Error: (204) AEROSPIKE_ERR_INDEX
aql> select * from test.myset where state = 'key1'
0 rows in set (0.000 secs)
Error: (201) AEROSPIKE_ERR_INDEX_NOT_FOUND
有人可以帮我弄这个吗。我搜索了那个错误,但没有找到任何信息。谢谢你。