2014-08-28 31 views
0

I'm與客體AppEngine上工作,我嘗試添加一個cron作業刪除所有臨時實體這比一小時以上:物化多個過濾器與cron作業doesn't工作

Iterable<Key<Entry>> allKeys = ofy().load().type(Entry.class) 
            .filter("temporary", true) 
            .filter("createdAt", oneHourAgo).keys(); 
if(allKeys != null){ 
    ofy().delete().keys(allKeys); 
} 

但我執行appengine服務器上的cron作業時總是會收到異常:

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> 

有人知道爲什麼會發生這種情況嗎?該工作工作,如果我刪除:

.filter("createdAt", oneHourAgo) 
+0

有數據商店 「createdAt」 創建的索引? – Andromeda 2014-08-28 11:41:10

+0

是索引是爲兩者創建的(createdAt和臨時)! – Weini 2014-08-28 11:44:28

回答

1

當你使用你的應用程序與開發服務器,開發服務器試圖找出你需要的指標,並自動將它們放置在索引定義文件。由於您在cron作業中使用此查詢,因此開發服務器無法幫助您。您需要手動爲該索引添加定義。

Java Datastore Index Configuration

+0

感謝您的快速回答!我用建議的xml代碼添加了一個datastore-indexes.xml,它工作。 – Weini 2014-08-28 12:26:22