我想在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;
索引我不知道我在做什么错在这里,我知道它是与过滤器有问题,因为如果我把它们注释掉查询执行罚款。那么我做错了什么?
我建议您重新阅读文档https://cloud.google.com/appengine/docs/java/config/indexconfig - 有什么不清楚的是您可以为WEB-INF /数据存储库中的数据存储区索引指定配置-indexes.xml,在您的应用程序的war /目录中。 '其次,你还应该了解一下围绕平等过滤器的限制。 https://cloud.google.com/appengine/docs/java/datastore/queries#Java_Restrictions_on_queries - 即使您创建了索引,您也只能注意到“单个查询可能不会使用多于一个的不等式比较property' –