aerospike-client-java icon indicating copy to clipboard operation
aerospike-client-java copied to clipboard

Question. QueryPolicy.filterExp is use by 2nd index?

Open boojongmin opened this issue 3 years ago • 2 comments

I read this https://github.com/aerospike/aerospike-client-java/issues/33?fbclid=IwAR2PBkdaDZKYXA15B50B9muK8M5f2YcdcyssbXysW8gADlA2wM17bfHbyaM

but I need search multiple bin with index.

aerospikeClient.createIndex(
    null, "hello", "hello",
    "idx_1", "hello1", IndexType.STRING,
    IndexCollectionType.DEFAULT
).awaitFirstOrNull()

aerospikeClient.createIndex(
    null, "hello", "hello",
    "idx_2", "hello2", IndexType.STRING,
    IndexCollectionType.DEFAULT
).awaitFirstOrNull()


val policy = QueryPolicy()
policy.filterExp = Exp.build(
        Exp.and(
            Exp.eq(Exp.bin("hello1", Exp.Type.STRING), Exp.`val`("asdf")),
            Exp.eq(Exp.bin("hello2", Exp.Type.STRING), Exp.`val`("defg"))
        ),
)

val v = aerospikeClient.query(policy, statement).awaitFirstOrNull()

is this code will use index?

and... how I know search rules like sql explain

thank you

boojongmin avatar May 04 '21 05:05 boojongmin

There is still a limit of one index filter (statement.setFilter()) per query, so either "idx_1" or "idx_2" could be used, but not both.

Expression filters (policy.filterExp) are applied after the index is used and can reference any combination of bins in the returned record. Therefore, your code should work, but only one index will be traversed.

BrianNichols avatar May 04 '21 17:05 BrianNichols

@BrianNichols thank for your appreciate comment. It is many helps for me. :)

boojongmin avatar May 05 '21 12:05 boojongmin