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

标签 google-app-engine android-studio google-cloud-endpoints google-cloud-datastore objectify

我使用 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 时如何更改它吗?

最佳答案

创建 datastore-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>

关于google-app-engine - 在基于 Android-Studio 的项目中为 AppEngine 创建综合索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34375358/

相关文章:

java - 将图像从 Android 客户端发送到 AppEngine Cloud Endpoint

java - 使用 JSF 2.2 的 Google App Engine 中的文件上传错误

Android Studio with opencv for android ndk, opencv header files not found

java - Cloud Endpoints 为作为命名参数传递的特殊字符生成 HTTP 404

json - Android Studio Gradle错误:缺少project_info对象

java - 由于 android Studio 中的 nullpointerException,应用程序崩溃

google-app-engine - 如何在 Google Cloud Endpoints 中允许 CORS?

google-app-engine - Channel API (GAE) 中的消息格式?

Python:对导入工作原理的误解

google-app-engine - 使用 Google App Engine 作为 CDN