Read with secondary indexes

Hi, all this is a continuation of our discussion at Mongo upsert-like capability? - #24 by Joshua_Buss.

My main problem now is on the read path. When I try to query for the records by other bins, I’m getting AEROSPIKE_ERR_INDEX_NOT_FOUND when I can clearly see the secondary index on my namespace/set in AMC…

>>> query = as_client.query(AS_NS, AS_SET)
>>> query.select('value', 'ts')

>>> from aerospike import predicates as p
>>> query.where( p.equals('channel', "WEB") )

>>> def print_result((key, metadata, record)):
...   print (key, record)
...
>>> query.foreach( print_result)
Traceback (most recent call last):
  File "", line 1, in 
Exception: (201L, 'AEROSPIKE_ERR_INDEX_NOT_FOUND', 'src/main/aerospike/aerospike_query.c', 223)

what does

 aql> show indexes

output look like

I would check to see if the secondary index is on the correct namespace and set and with similar bin type or not. In your case secondary index should be on AS_NS, AS_SET of TEXT type.

How many nodes cluster do you have ??

– R

aql> show indexes
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
| ns       | bins      | set          | num_bins | state | indexname | sync_state | type         |
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
| "signal" | "brand"   | "brandstats" | 1        | "RW"  | "brand"   | "synced"   | "TEXT"       |
| "signal" | "ts"      | "brandstats" | 1        | "RW"  | "ts"      | "synced"   | "INT SIGNED" |
| "signal" | "channel" | "brandstats" | 1        | "RW"  | "channel" | "synced"   | "TEXT"       |
| "signal" | "metric"  | "brandstats" | 1        | "RW"  | "metric"  | "synced"   | "TEXT"       |
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
4 rows in set (0.001 secs)
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
| ns       | bins      | set          | num_bins | state | indexname | sync_state | type         |
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
| "signal" | "brand"   | "brandstats" | 1        | "RW"  | "brand"   | "synced"   | "TEXT"       |
| "signal" | "ts"      | "brandstats" | 1        | "RW"  | "ts"      | "synced"   | "INT SIGNED" |
| "signal" | "channel" | "brandstats" | 1        | "RW"  | "channel" | "synced"   | "TEXT"       |
| "signal" | "metric"  | "brandstats" | 1        | "RW"  | "metric"  | "synced"   | "TEXT"       |
+----------+-----------+--------------+----------+-------+-----------+------------+--------------+
4 row

I’m currently using a 3 node cluster.

Joshua,

Show indexes shows the indexes present on all the nodes … Here I see only two tables and your’s is a 3 node cluster. Is the output truncated ?

If not then problem is one of the node not in sync with other nodes in terms of index metadata … To identify why would that happen can you share the log from the node where the secondary is missing. To identify which nodes does not have index you can run the following command

$> asinfo -v 'sindex-list:' -p <port> -h <ip>

Default value of port is 3000 you may not specify is if servers are running on default port

– R