Primary Key search




I’m tryingo to create a primary Key query with java client.

If I have this set:

±—±-----------+ | id | name | ±—±-----------+ | 3 | “jose” | | 1 | “david” | | 2 | “luis” |

With PK equasl id field . I can do the next query in aql

select * from test.tabletest where PK = ‘1’

and aql shows me

| id | name | ±—±----------+ | 1 | “david” | ±—±----------+

I want to make the same with java. I had tryed to create a filter like this:

com.aerospike.client.query. Filter.equal(“PK”,“1”)); but when I am executing the nex method in aeropike recordSet the method throws the follow exception:

com.aerospike.client.AerospikeException: Error Code 204: Index error

Anybody can help me.



It looks like 1 is a long in your table not a string. Try Filter.equal(“PK”, 1).


But by the error message it looks like you haven’t indexed the field you are querying on.


I don’t believe filters work on the primary key either, so you’ll have to create a second field that contains the data of the primary key again and index it.

Limited to 3 posts per topic, so continuing my post here…

For my use case I needed to do a range based query on our primary key. So we had to create a second field to do the range based query on. The simple equals case as was mentioned works by just doing a direct access with the key.


I can’t create a secondary index for each table PK. My problem is the limiatation of the number of secondary index (only 256). In my use case I can’t detreminate the table number because is a generic solution.

Thank you for you fast answer.


Aerospike is a key-value store so if you’re storing it with that primary key, you just get it with that primary key.

You don’t need to perform a query, that’s only used for selecting multiple records that match a secondary index or a UDF method.

Just get the record you want directly by the key in the driver you’re using.


Hi Jose

In AQL you would use the following to ‘select’ using the primary key:

		SELECT bn2,bn3,bn4  FROM test.demo WHERE PK = '10'

Here is the equivalent code using the Java client

	Record record = client.get(policy, new Key("test", "demo", "10"), "bn2", "bn3", "bn4");

I hope this helps