I have tested in Java, it works. Your issue may be that you have written records with sendKey not set to true in the WritePolicy.
Aerospike by default does not store your string key - it stores the 20 byte RIPEMD160 hash only. If you want to use Exp.key(Type.STRING) - the key also has to be stored in Aeropike which you can do, by setting (Java client) WritePolicy.sendKey
set to true.
I will share the code snippet here - tested in my Jupyter Notebook environment;
//Run SI query
Statement stmt = new Statement();
stmt.setNamespace("test");
stmt.setSetName("testset");
//Filter key by expressions
Expression recKeyExp = Exp.build(
Exp.regexCompare(".*[2,3]", RegexFlag.ICASE|RegexFlag.NEWLINE, Exp.key(Exp.Type.STRING))
);
QueryPolicy qp = new QueryPolicy();
qp.filterExp = recKeyExp;
RecordSet rs = client.query(qp, stmt);
while(rs.next()){
Record r = rs.getRecord();
Key thisKey = rs.getKey();
System.out.println(thisKey);
System.out.println(r);
}
Output:
test:testset:key2:c10b2c764e604c439039804ec947fa2b18520d1a
(gen:1),(exp:453831888),(bins:(name:Jill),(age:20))
test:testset:key3:10fd8f59adf1833152e439a2e03c19efcb12c145
(gen:1),(exp:453831888),(bins:(name:James),(age:38))
My test data is:
Initialized the client and connected to the cluster.
key0 : (gen:1),(exp:453831888),(bins:(name:Sandra),(age:34))
key1 : (gen:1),(exp:453831888),(bins:(name:Jack),(age:26))
key2 : (gen:1),(exp:453831888),(bins:(name:Jill),(age:20))
key3 : (gen:1),(exp:453831888),(bins:(name:James),(age:38))
key4 : (gen:1),(exp:453831888),(bins:(name:Jim),(age:46))
key5 : (gen:1),(exp:453831888),(bins:(name:Julia),(age:62))
key6 : (gen:1),(exp:453831888),(bins:(name:Sally),(age:32))
key7 : (gen:1),(exp:453831888),(bins:(name:Sean),(age:24))
key8 : (gen:1),(exp:453831888),(bins:(name:Sam),(age:12))
key9 : (gen:1),(exp:453831888),(bins:(name:Susan),(age:42))
Data was added using aql:
aql> set key_send true
aql> run 'insert.aql'
where, insert.aql is:
INSERT INTO test.testset (PK, name, age) VALUES ('key1', 'Jack', 26)
INSERT INTO test.testset (PK, name, age) VALUES ('key2', 'Jill', 20)
INSERT INTO test.testset (PK, name, age) VALUES ('key3', 'James', 38)
INSERT INTO test.testset (PK, name, age) VALUES ('key4', 'Jim', 46)
INSERT INTO test.testset (PK, name, age) VALUES ('key5', 'Julia', 62)
INSERT INTO test.testset (PK, name, age) VALUES ('key6', 'Sally', 32)
INSERT INTO test.testset (PK, name, age) VALUES ('key7', 'Sean', 24)
INSERT INTO test.testset (PK, name, age) VALUES ('key8', 'Sam', 12)
INSERT INTO test.testset (PK, name, age) VALUES ('key9', 'Susan', 42)
INSERT INTO test.testset (PK, name, age) VALUES ('key0', 'Sandra', 34)
Hope that helps.