Is it possible to use expression filters on maps to select records with a specific map key matching a specific value? I’m only seeing options in the API for separate MAPKEYS and MAPVALUES filters. Is there a way to accomplish this with expressions, or would I just need to do it in a UDF or in post processing on the application side?
Not sure that I follow, I think you want to find a record where a particular map bin contains a particular key, value pair where the key equals some key and the value equals some value. If not, please try to clarify your request, maybe with a code example.
For matching a key and value, you should be able to use the
Such an expression would look something like this:
// Filter to return record where the map stored in the bin named "binName" contains the key // "mapKey" and the value stored at that they equals 5. eq( map_get_by_key( type.integer, context, result_type.value, as_exp_str("mapKey"), bin_map("binName")), as_exp_int(5))
Yes, that’s what I’m trying to do. I figured out how to do this in the Go client, but it took a while looking at the expression tests and trying different things from that. It looks the same as what you shared, so looks like this is the right way.
queryPolicy.FilterExpression = aerospike.ExpEq( aerospike.ExpMapGetByKey(aerospike.MapReturnType.VALUE, aerospike.ExpTypeINT, aerospike.ExpStringVal("some_key"), aerospike.ExpMapBin("bin_name")), aerospike.ExpIntVal(5), )