在基于 Android-Studio 的项目中为 AppEngine 创建综合索引

Creating a Composite Index for AppEngine in Android-Studio-based project

我使用 Android Studio 创建了一个 Android 项目及其对应的后端 AppEngine Endpoints。我有一个正在使用 Objectify 的数据存储。该系统运行良好,直到我在我的查询中添加了一个过滤器(以仅显示特定的给定电子邮件)。

Query<Report> query = ofy().load().type(Report.class).filter("email", user.getEmail()).order("email").order("-when").limit(limit);

这是 POJO 数据存储实体:

@Entity
public class Report {
    @Id
    Long id;

    String who;

    @Index
    Date when;

    String what;

    @Index
    String email;
}

但是,当我尝试测试 Google API Explorer 时收到这样的错误:

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>

据我了解,我只需要创建一个包含特定字段电子邮件和时间的复合索引,以及它们的特定排序方向。

但是,我找到的大多数文档都告诉我编辑 datastore-indexes.xml

App Engine predefines a simple index on each property of an entity. An App Engine application can define further custom indexes in an index configuration file named datastore-indexes.xml, which is generated in your application's /war/WEB-INF/appengine-generated directory.

不幸的是,这个文件似乎不存在于我的项目中。

有人熟悉在使用 Android Studio 时更改此设置的方法吗?

创建数据存储-indexes.xml 文件并将其放入/WEB-INF/ 文件夹中。内容将如下所示:

<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>