我试图在aerospike中存储地图,并根据地图的关键点获取数据。查询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
有人可以帮助我。我搜索了那个错误,但没有找到任何信息。谢谢。
在我们深入挖掘之前,你的意思是做'where state ='而不是'where status ='? – Aaron
@Aaron,我试着使用状态,它给出了一个不同的错误。相应地更新问题。 –