DatastoreNeedIndexException:找不到匹配的索引.使用Objectify

The*_*bee 2 java google-app-engine objectify google-cloud-datastore

在将我的代码部署到云后使用google appengine时出现此错误,我使用objectify索引进行过滤.

这是我的包含索引的java类(Entity)文件

@Entity
public class Session{
   @Index private Integer year;
   @Index private Key<Institute> institute;
  //some other manipulation goes below
   }
Run Code Online (Sandbox Code Playgroud)

当我尝试使用objectify从数据存储区调用实体列表时

ofy().load().type(Session.class).filter("institute",t).order("year").list();//order by year
Run Code Online (Sandbox Code Playgroud)

它在我的控制台上抛出以下错误,下面的图像显示它,抱歉不太清楚

在此输入图像描述

And*_*gin 6

您需要将建议的索引定义添加到您的datastore-indexes.xml文件中.如果您没有此文件,则需要在/ war/WEB-INF /文件夹中创建它:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes
  autoGenerate="true">

    <datastore-index kind="Session" ancestor="false" source="manual">
        <property name="institute" direction="asc"/>
        <property name="year" direction="asc"/>
    </datastore-index>
</datastore-indexes>
Run Code Online (Sandbox Code Playgroud)

请注意,在开发服务器上测试应用程序时,大多数索引定义都可以自动生成,但有时测试每个可能的用例并不容易,手动定义可能更容易.