Reputation: 79
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
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