我正在使用一些方法部署一个小后端。其中一个进行简单的查询来检索对象列表。方法是这样的:
@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/