How to filter Google Content Store data based on a property that is an array using Java library

Viewed 683

I have a Datastore where one property contains an array of strings. Each Entity can have a different size of that array. I want to make a query and filter upon the content of the array in each Entity.

I currently generate a set of filters, one for each required string in the array. I'm then building up a composite filter to be used in an EntityQuery. The filters are generated like this:

// arrayProperty is the name on the property in my Datastore that contains the array of strings.
List<PropertyFilter> pathFilters = Arrays.stream(new String[] {"a","b","c"})
    .map(s -> PropertyFilter.eq("arrayProperty", s))
    .collect(Collectors.toList());

This will however match both entities with arrayProperty = [a,b,c] and arrayProperty = [a,b,c,d].

Can I use Google Cloud Datastore Query from JAVA library in com.google.cloud.datastore to filter out entities whose property value is a particular array with exact the same elements (no more, no less and order independent)? Maybe by some sort of size filter or a completely different query/filter. Or could I use the GQL?

1 Answers
Related