Sandy
Sandy

Reputation: 79

Filter and sort in GAE

I am trying to filter and sort data in my Kind="sensordata" in Google datastore

Query<com.google.cloud.datastore.Entity> query 
= Query.newEntityQueryBuilder()
       .setKind("sensordata")                               
       .setFilter(PropertyFilter.eq("deviceguid",deviceGuid))
       .setOrderBy(OrderBy.desc("timestamp"))
       .build();

All my fields are indexed. If i remove either of .SetFilter or .setOrderBy, its working fine.

Any idea what is going wrong?

Thanks Sandy

Upvotes: 0

Views: 327

Answers (1)

Mar Cial R
Mar Cial R

Reputation: 946

I suspect either an index for deviceguid+timestamp is missing from your datastore-indexes.xml or index.yaml:

<datastore-index kind="Sensordata" ancestor="false">
    <property name="deviceguid" direction="asc" />
    <property name="timestamp" direction="desc" />
</datastore-index>

or you haven't uploaded it.

The reason is that queries with simple filters or sort orders can use automatic indexes but "Other forms of query require their indexes to be specified in the index configuration file"

Upvotes: 2

Related Questions