【问题标题】:Objectify multiple filters doesn´t work with cron jobObjectify 多个过滤器不适用于 cron 作业
【发布时间】:2014-10-22 06:17:52
【问题描述】:

我正在 appengine 上使用 objectify,我尝试添加一个 cron 作业来删除所有超过一小时的临时实体:

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)

【问题讨论】:

  • 数据存储中是否为“createdAt”创建了任何索引?
  • 是的,索引是为两者创建的(createdAt 和temporary)!

标签: java google-app-engine cron objectify


【解决方案1】:

当您将应用程序与开发服务器一起使用时,开发服务器会尝试找出您需要哪些索引并将它们自动放入索引定义文件中。由于您在 cron 作业中使用此查询,因此开发服务器无法在此处为您提供帮助。您需要手动添加此索引的定义。

Java Datastore Index Configuration

【讨论】:

  • 感谢您的快速答复!我用建议的 xml 代码添加了一个 datastore-indexes.xml 并且它起作用了。
猜你喜欢
  • 2013-02-06
  • 2016-07-22
  • 2014-04-26
  • 2012-10-04
  • 2015-10-29
  • 2020-05-18
  • 2017-11-12
  • 2012-04-28
  • 2019-05-23
相关资源
最近更新 更多