问题描述
我使用Android Studio创建了一个Android项目,以及它的后端AppEngine Endpoints对应项。我有一个我正在使用Objectify的数据存储。系统运行良好,直到我添加了一个过滤器到我的查询(仅显示特定给定的电子邮件)。
查询< Report>查询= ofy()。load()。type(Report.class).filter(email,user.getEmail())。order(email)。order( - when)。limit(limit);
这是POJO数据存储实体:
@Entity
public class Report {
@Id
Long id;
字符串谁;
@Index
日期;
字符串是什么;
@Index
字符串电子邮件;
}
但是,我试图在Google API Explorer中收到这样的错误测试它:
com.google.appengine.api.datastore.DatastoreNeedIndexException:找不到匹配的索引。
此查询的建议索引是:
< property name = \when \direction = \desc\/>
< / datastore-index>
据我所知,我只需创建一个包含特定字段email和when的复合索引,不过,我发现的大多数文档都告诉我要编辑 datastore-indexes.xml
。
不幸的是,这个文件似乎并不存在于我的项目中的任何地方。
创建datastore-indexes.xml文件
创建datastore-indexes.xml文件并放在 / WEB-INF /
文件夹中。内容将如下所示:
< datastore-indexes
autoGenerate =true>
< property name = \when \direction = \desc\/>
< / datastore-index>
< / datastore-indexes>
I used Android Studio to create both an Android project, and its backend AppEngine Endpoints counterpart. I have a datastore for which I am using Objectify. The system worked great, until I added a filter to my Query (to show only specific given emails).
Query<Report> query = ofy().load().type(Report.class).filter("email", user.getEmail()).order("email").order("-when").limit(limit);
This is the POJO Datastore Entity:
@Entity
public class Report {
@Id
Long id;
String who;
@Index
Date when;
String what;
@Index
String email;
}
However, I receive such an error from the Google API Explorer when I attempt to test it:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind=\"AccessReport\" ancestor=\"false\" source=\"manual\">
<property name=\"email\" direction=\"asc\"/>
<property name=\"when\" direction=\"desc\"/>
</datastore-index>
As I understand it, I simply need to create a composite index including the specific fields email and when, with their specific sort direction.
However, most documentation that I find tell me to edit datastore-indexes.xml
.
Unfortunately, this file does not seem to exist anywhere in my project.
Is anyone familiar with the way to change this when working with Android Studio?
Create datastore-indexes.xml file and put it in /WEB-INF/
folder. The content will look like this:
<datastore-indexes
autoGenerate="true">
<datastore-index kind=\"AccessReport\" ancestor=\"false\" source=\"manual\">
<property name=\"email\" direction=\"asc\"/>
<property name=\"when\" direction=\"desc\"/>
</datastore-index>
</datastore-indexes>
这篇关于在基于Android-Studio的项目中为AppEngine创建综合索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!