Comparing two different properties in GQL

221 views Asked by At

The following two GQL queries work:

SELECT * FROM Customer WHERE FirstName = "John"
SELECT * FROM Customer WHERE Rating > 4.0

But, when I combine them...

SELECT * FROM Customer WHERE FirstName = "John" AND Rating > 4.0

... I get an empty result set even though running the queries individually finds the entity that I am looking for. How do I compare more than one property?

Here's what I've done:

  • I made sure that at least one entity exists where both is true.

gql

  • I created an index for the properties:

enter image description here

1

There are 1 answers

0
arao6 On BEST ANSWER

Patrick Costello at Google answered my question:

You need an index on exactly (FirstName, Rating). Your current index cannot answer that query.

Basically, the problem was that I created an index on all the properties. However, each "type" of query (in this case, a query comparing FirstName and Rating) needs its own index (i.e. an index with just FirstName and Rating). I hope this helps someone!