java - 找不到匹配的索引 - GAE

标签 java google-app-engine google-cloud-firestore google-cloud-endpoints-v2

我正在使用一些方法部署一个小后端。其中一个进行简单的查询来检索对象列表。方法是这样的:

@ApiMethod(path = "getMessagesByCity", name = "getMessagesByCity", httpMethod = ApiMethod.HttpMethod.POST)
    public MessageResponse getMessagesByCity(@Named("City_id") Long city) {
        MessageResponse response = new MessageResponse();
        List<Message> message = ofy().load().type(Message.class).filter("city", city).list();
        response.response = 200;
        return response;
    }

这是 Message 类:

@Entity
public class Message {
    @Id 
    private Long id;
    private String name;
    @Index
    private Long city;
    ...
}

我读过很多帖子,所有帖子都提到这可能是因为 datastore-indexes.xml 没有自动更新所致。然而,Google 文档是这样说的( https://cloud.google.com/appengine/docs/standard/python/config/indexconfig ):

Every Cloud Datastore query made by an application needs a corresponding index. Indexes for simple queries, such as queries over a single property, are created automatically.

所以,接下来,我认为索引相关的文件对我来说不是必需的。

如果我使用简单查询执行方法“getMessagesByCity”:

List<Message> message = ofy().load().type(Message.class).filter("city", city).list();

后端向我返回错误 503 并包含以下日志消息:

"com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. An index is missing but we are unable to tell you which one due to a bug in the App Engine SDK. If your query only contains equality filters you most likely need a composite index on all the properties referenced in those filters."

有什么想法吗?怎么解决呢?

最佳答案

您需要上传索引配置,以便数据存储区将开始使用此命令接受带有自定义投影的查询。

gcloud app deploy index.yaml

参见https://cloud.google.com/datastore/docs/concepts/indexes有关数据存储区查询处理和索引的更多信息。

关于java - 找不到匹配的索引 - GAE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50840618/

相关文章:

java - JAVA动态类引用变量?

java - Spring Boot 为 POST 到未知 URL 返回 405 而不是 404

html - CSS 文件仅部分适用于 Google App Engine

javascript - 如何等待React Native Image Picker回调函数响应?

swift - 将 Firestore 添加到我的项目会导致我的实时数据库查询出错

dart - 如何将某人的用户 ID 存储在我的 friend 集合中以及如何使用带有 flutter 的 firestore 检索该用户的数据?

java - 我怎样才能简化这个正则表达式?

java - 如何为组件设置坐标?

java - 是否可以使用 Blobstore API 在 GCS 中设置上传的文件名

google-app-engine - 在 App Engine 上使用 OAuth2 的 IMAP