How to query bins on secondary indexes?


#1

I tried this:

CREATE INDEX recipient_id ON gifts.received (recipient) STRING

from the example provided in Aerospike’s documentation:

CREATE INDEX user_age_idx ON users.profiles (age) NUMERIC

But when I make a query on it:

SELECT * FROM gifts.received WHERE recipient = "rfoazicxqezrxivc"

Here’s what I get as a response:

0 rows in set (0.000 secs)
Error: (201) AEROSPIKE_ERR_INDEX_NOT_FOUND

But when I display the whole set:

SELECT * FROM gifts.received
+--------------------+--------------------+------------+
| sender             | recipient          | time_sent  |
+--------------------+--------------------+------------+
| "trezretazecdsfdr" | "rfoazicxqezrxivc" | 1489513314 |
+--------------------+--------------------+------------+
1 row in set (0.344 secs)

Also, the secondary key seems to be OK:

show indexes
+---------+-------------+-----------+------------+-------+----------------+-------------+------------+----------+
| ns      | bin         | indextype | set        | state | indexname      | path        | sync_state | type     |
+---------+-------------+-----------+------------+-------+----------------+-------------+------------+----------+
| "gifts" | "recipient" | "NONE"    | "received" | "RW"  | "recipient_id" | "recipient" | "synced"   | "STRING" |
+---------+-------------+-----------+------------+-------+----------------+-------------+------------+----------+
1 row in set (0.000 secs)
OK

So I don’t understand… The value is correct, the bin appears in the set, but when I try to make a query as shown in the documentation, it doesn’t work. I don’t see what I did that’s fundamentally different from the documentation… I did everything it says.


#2

Aerospike Version? I tested on 3.11.

    aql> CREATE INDEX recipient_id ON test.received (recipient) STRING
    OK, 1 index added.

    aql> insert into test.received (pk, sender, recipient, timestamp) values ("key1", "trezretazecdsfdr", "rfoazicxqezrxivc", 1489513314)
    OK, 1 record affected.

    aql> select * from test.received
    +--------------------+--------------------+------------+
    | sender             | recipient          | timestamp  |
    +--------------------+--------------------+------------+
    | "trezretazecdsfdr" | "rfoazicxqezrxivc" | 1489513314 |
    +--------------------+--------------------+------------+
    1 row in set (0.557 secs)

    aql> select * from test.received where recipient="rfoazicxqezrxivc"
    +--------------------+--------------------+------------+
    | sender             | recipient          | timestamp  |
    +--------------------+--------------------+------------+
    | "trezretazecdsfdr" | "rfoazicxqezrxivc" | 1489513314 |
    +--------------------+--------------------+------------+
    1 row in set (0.025 secs)

aql> select * from test.received where recipient = "rfoazicxqezrxivc"
+--------------------+--------------------+------------+
| sender             | recipient          | timestamp  |
+--------------------+--------------------+------------+
| "trezretazecdsfdr" | "rfoazicxqezrxivc" | 1489513314 |
+--------------------+--------------------+------------+
1 row in set (0.014 secs)

aql>

#3

3.11.1.1

I updated everything before doing this.