-1

I'm looking for way how to query in datastore by list of properties.

So, i have a simple Entity:

@Data
@Entity(name = APPLICATION_KIND)
public class ApplicationEntity {

    @Id
    private String Id;

    private String appId;

    private String name;

    private String status;
}

i would like to do lookup by list of appIds. However, seems Datastore doesn't provide such possibility.

DatastoreTemplate provides only one possibility - findAllById but it doesn't work neither for other fields nor along with other filters (e.g. by status).

Unfortunately, StructuredQuery.PropertyFilter doesn't provide such possibility as well. StructuredQuery.CompositeFilter has only and but doesn't have neither or nor in.

Probably someone faced with the same issue and workaround it somehow?

user2738882
  • 1,161
  • 1
  • 20
  • 38
  • Afaik `IN` operator is not supported in Datastore, you wil either have to do separate queries and merge results or use libraries that iare already doing it under the hood. – Emil Gi Nov 09 '20 at 14:49

2 Answers2

0

You can pass each property list in StructuredQuery.PropertyFilter as an array; you can follow this link: https://cloud.google.com/datastore/docs/concepts/queries#array_values

And, for OR and IN you can write a GQL query and execute the query like this:

SELECT * FROM analysis WHERE concepts CONTAINS concept;

Here, the analysis entity contains a list of concepts.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

IN operator is actually supported in Datastore but OR is not. Please refer to this documentation for more info.

You can actually do something like this:

SELECT * FROM APPS WHERE appId IN (abc, xyz, ...)

Methkal Khalawi
  • 2,368
  • 1
  • 8
  • 13