从 aerospike 上的二级索引查询
Query from secondary index on aerospike
我正在考虑将 aerospike 用于我们的一个项目。所以我目前创建了一个 3 节点集群并在其上加载了一些数据。
样本数据
ns: imei
设置:imei_data
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| imsi | fcheck | lcheck | msc | fcheck_epoch | lcheck_epoch |
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| "413010324064956" | "2017-03-01 14:30:26" | "2017-03-01 14:35:30" | "13d20b080011044917004100" | 1488358826 | 1488359130 |
| "413012628090023" | "2016-09-21 10:06:49" | "2017-09-16 13:54:40" | "13dc0b080011044917006100" | 1474432609 | 1505550280 |
| "413010130130320" | "2016-12-29 22:05:07" | "2017-10-09 16:17:10" | "13d20b080011044917003100" | 1483029307 | 1507546030 |
| "413011330114274" | "2016-09-06 01:48:06" | "2017-10-09 11:53:41" | "13d20b080011044917003100" | 1473106686 | 1507530221 |
| "413012629781993" | "2017-08-16 16:03:01" | "2017-09-13 18:10:48" | "13dc0b080011044917004100" | 1502879581 | 1505306448 |
然后我使用 AQL 在 lcheck_epoch 上创建了一个二级索引,因为我想根据日期进行查询。
create index idx_lcheck on imei.imei_data (lcheck_epoch) NUMERIC
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| ns | bin | indextype | set | state | indexname | path | type |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| "imei" | "lcheck_epoch" | "NONE" | "imei_data" | "RW" | "idx_lcheck" | "lcheck_epoch" | "NUMERIC" |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
当我执行
select imsi from imei.imei_data where idx_lcheck=1476165806
我正在
Error: (204) AEROSPIKE_ERR_INDEX
请说明。
您在查询中使用的是索引名称,而不是 bin 名称。试试这个:
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch=1476165806
或者
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch BETWEEN 1490000000 AND 1510000000
请注意,您可以使用 predicate filtering through several of the language clients (Java, C, C#, Go). For example the PredExp class of the Java client (see examples 进行更复杂的查询。)
我正在考虑将 aerospike 用于我们的一个项目。所以我目前创建了一个 3 节点集群并在其上加载了一些数据。
样本数据
ns: imei
设置:imei_data
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| imsi | fcheck | lcheck | msc | fcheck_epoch | lcheck_epoch |
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| "413010324064956" | "2017-03-01 14:30:26" | "2017-03-01 14:35:30" | "13d20b080011044917004100" | 1488358826 | 1488359130 |
| "413012628090023" | "2016-09-21 10:06:49" | "2017-09-16 13:54:40" | "13dc0b080011044917006100" | 1474432609 | 1505550280 |
| "413010130130320" | "2016-12-29 22:05:07" | "2017-10-09 16:17:10" | "13d20b080011044917003100" | 1483029307 | 1507546030 |
| "413011330114274" | "2016-09-06 01:48:06" | "2017-10-09 11:53:41" | "13d20b080011044917003100" | 1473106686 | 1507530221 |
| "413012629781993" | "2017-08-16 16:03:01" | "2017-09-13 18:10:48" | "13dc0b080011044917004100" | 1502879581 | 1505306448 |
然后我使用 AQL 在 lcheck_epoch 上创建了一个二级索引,因为我想根据日期进行查询。
create index idx_lcheck on imei.imei_data (lcheck_epoch) NUMERIC
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| ns | bin | indextype | set | state | indexname | path | type |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| "imei" | "lcheck_epoch" | "NONE" | "imei_data" | "RW" | "idx_lcheck" | "lcheck_epoch" | "NUMERIC" |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
当我执行
select imsi from imei.imei_data where idx_lcheck=1476165806
我正在
Error: (204) AEROSPIKE_ERR_INDEX
请说明。
您在查询中使用的是索引名称,而不是 bin 名称。试试这个:
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch=1476165806
或者
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch BETWEEN 1490000000 AND 1510000000
请注意,您可以使用 predicate filtering through several of the language clients (Java, C, C#, Go). For example the PredExp class of the Java client (see examples 进行更复杂的查询。)