问题
I´m working with objectify on appengine, I tried to add a cron job to delete all temp entities which are older than an hour:
Iterable<Key<Entry>> allKeys = ofy().load().type(Entry.class)
.filter("temporary", true)
.filter("createdAt", oneHourAgo).keys();
if(allKeys != null){
ofy().delete().keys(allKeys);
}
but i always get an Exception when executing the cron job on the appengine server:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind="Entry" ancestor="false" source="manual">
<property name="temporary" direction="asc"/>
<property name="createdAt" direction="asc"/>
</datastore-index>
does anybody know why this happens? The job works if I remove:
.filter("createdAt", oneHourAgo)
回答1:
When you use your app with a Development server, the development server tries to figure out which indexes you need and places them in the index-definition file automatically. Since you use this query in a cron job, the development server cannot help you here. You will need to add a definition for this index manually.
Java Datastore Index Configuration
来源:https://stackoverflow.com/questions/25547895/objectify-multiple-filters-doesn%c2%b4t-work-with-cron-job