With Expressions, it is possible to do regex search on Key, but as @meher said, you must store the key on the server. You can either store it via sendKey set to true, or you can also store in a record bin.
Code below shows example if you do sendKey true. (similar code will be applicable if the string was in the bin with exp build call modified to use string in bin instead that of the stored key).
I populated the test data (using aql) as follows:
INSERT INTO test.testset (PK, name, age) VALUES ('jacksapplekey1', 'Jack', 26)
INSERT INTO test.testset (PK, name, age) VALUES ('jillgrapekey2', 'Jill', 20)
INSERT INTO test.testset (PK, name, age) VALUES ('mangokey3', 'James', 38)
INSERT INTO test.testset (PK, name, age) VALUES ('Jimkey4apple', 'Jim', 46)
INSERT INTO test.testset (PK, name, age) VALUES ('JuliaGrapekey5', 'Julia', 62)
INSERT INTO test.testset (PK, name, age) VALUES ('SallyMANGOkey6', 'Sally', 32)
INSERT INTO test.testset (PK, name, age) VALUES ('SeanaPPlekey7', 'Sean', 24)
INSERT INTO test.testset (PK, name, age) VALUES ('SamGRAPEkey8', 'Sam', 12)
INSERT INTO test.testset (PK, name, age) VALUES ('Susankey9', 'Susan', 42)
INSERT INTO test.testset (PK, name, age) VALUES ('SandraPeachkey0', 'Sandra', 34)
Then I added a secondary index on age bin (just for fun). So I will select records based on an age range AND that have apple (with case ignored flag) in their primary key.
Here is the code in Java: (Aerospike Golang client … should have similar APIs available.)
//Needed imports
import com.aerospike.client.query.Statement;
import com.aerospike.client.query.Filter;
import com.aerospike.client.query.RecordSet;
import com.aerospike.client.policy.QueryPolicy;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.exp.Exp.Type;
import com.aerospike.client.query.RegexFlag;
//Run SI query
Statement stmt = new Statement();
stmt.setNamespace("test");
stmt.setSetName("testset");
stmt.setFilter(Filter.range("age", 20,30));
QueryPolicy qp = new QueryPolicy();
Exp exp = Exp.val(false); //init to false
exp = Exp.regexCompare("^.*apple.*",RegexFlag.ICASE,Exp.key(Type.STRING));
qp.filterExp = Exp.build(exp);
RecordSet rs = client.query(qp, stmt);
while (rs.next()){
Record r = rs.getRecord();
Key k = rs.getKey(); //Double check the key retrireved
System.out.println(r);
System.out.println(k);
}
And the output: (Jim has apple in key, but age is out of SI filter range)
(gen:1),(exp:409022737),(bins:(name:Sean),(age:24))
test:testset:SeanaPPlekey7:ef8ea2cf3c6f526b567acdae097ba99e6f9def2d
(gen:1),(exp:409022737),(bins:(name:Jack),(age:26))
test:testset:jacksapplekey1:acbb041d06610ece7dc1e3bea2fd0c3916cde7bb