【发布时间】:2016-02-28 18:29:08
【问题描述】:
我正在尝试在App Engine 中执行查询,此选择查询的 sql 版本将如下所示
"WHERE (personId ="+personId+" AND uploadedDate >"+lastCheckDate+") OR ("+personId ="+personId+" AND updatedDate >"+lastCheckDate+")"
在我的应用引擎后端,我创建了多个过滤器并使用CompositeFilterOperator 使用Objectify 组合过滤器
Filter f1 = new FilterPredicate("personId", FilterOperator.EQUAL,personId);
Filter f2 = new FilterPredicate("uploadDate", FilterOperator.GREATER_THAN,lastCheckDate);
Filter f3 = new FilterPredicate("updatedDate", FilterOperator.GREATER_THAN,lastCheckDate);
Filter final1 = CompositeFilterOperator.and(f1,f2);
Filter final2 = CompositeFilterOperator.and(f1,f3);
Filter qFilter = CompositeFilterOperator.or(final1,final2);
Query<CloudRecord> query = ofy().load().type(CloudRecord.class).filter(qFilter).limit(limit);
但是当我在我的 android 应用程序中调用它时出现此错误
com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
{
"code": 503,
"errors": [
{
"domain": "global",
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.\nThe suggested index for this query is:\n <datastore-index kind=\"CloudRecord\" ancestor=\"false\" source=\"manual\">\n <property name=\"personId\" direction=\"asc\"/>\n <property name=\"uploadDate\" direction=\"asc\"/>\n </datastore-index>\n\n",
"reason": "backendError"
}
],
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.\nThe suggested index for this query is:\n <datastore-index kind=\"CloudRecord\" ancestor=\"false\" source=\"manual\">\n <property name=\"personId\" direction=\"asc\"/>\n <property name=\"uploadDate\" direction=\"asc\"/>\n </datastore-index>\n\n"
}
所有这些字段都在类中索引
@Entity public class CloudRecord {
@Id
Long id;
@Index
long uploadDate;
@Index
long updatedDate;
@Index
String personId;
我不确定我在这里做错了什么,我知道这是过滤器的问题,因为如果我将它们注释掉,查询就会正常执行。那我做错了什么?
【问题讨论】:
-
我建议您重新阅读文档cloud.google.com/appengine/docs/java/config/indexconfig - 不清楚的地方` 您在应用程序的war/ 目录中的WEB-INF/datastore-indexes.xml 中指定数据存储索引的配置. ` 其次,您还应该了解有关不等式过滤器的限制。 cloud.google.com/appengine/docs/java/datastore/… - 即使你创建了你只能拥有的索引,你会注意到
a single query may not use inequality comparisons on more than one property
标签: android google-app-engine objectify