Java 应用程序引擎没有';t生成复合索引
我正在学习Udacity的“用Java开发可伸缩应用”教程,并尝试通过多个属性创建查询,但它不起作用 以下是Api方法:Java 应用程序引擎没有';t生成复合索引,java,google-app-engine,Java,Google App Engine,我正在学习Udacity的“用Java开发可伸缩应用”教程,并尝试通过多个属性创建查询,但它不起作用 以下是Api方法: @ApiMethod(name = "filterPlayground",path = "filterPlayground",httpMethod = HttpMethod.POST) public List<Conference> filterPlayground() { Query<Conference>query = ofy().load
@ApiMethod(name = "filterPlayground",path = "filterPlayground",httpMethod = HttpMethod.POST)
public List<Conference> filterPlayground()
{
Query<Conference>query = ofy().load().type(Conference.class).order("name");
query.filter("city = ","London");
query.filter("topics =", "Medical Innovations");
query.filter("month = ", 6);
return query.list();
}
@ApiMethod(name=“filterplayland”,path=“filterplayland”,httpMethod=httpMethod.POST)
公共列表过滤器平台()
{
Queryquery=ofy().load().type(Conference.class).order(“name”);
query.filter(“city=”,“London”);
query.filter(“topics=”,“Medical Innovations”);
query.filter(“month=”,6);
返回query.list();
}
以下是会议模型中的字段:
private static final String DEFAULT_CITY = "Default City";
@Index private List<String> topics;
@Index(IfNotDefault.class) private String city = DEFAULT_CITY;
@Index private int month;
private静态最终字符串DEFAULT\u CITY=“DEFAULT CITY”;
@索引私有列表主题;
@索引(IfNotDefault.class)私有字符串city=DEFAULT\u city;
@每月指数;
它只是显示所有的会议。我不明白为什么这样不行。顺便说一下,当我部署到localhost时,datastore-index-auto.xml总是空的
下面是测试的链接:
我希望有人能帮我。
关于几件事:
数据存储索引auto.xml
为空,因为在您的情况下不需要复合索引我也在同样的道路上工作,在这一点上也很挣扎。不管我做什么,datastore-index-auto.xml都没有被创建 我的解决办法如下: 1) 在文件夹:/conference/src/main/webapp/WEB-INF/中创建一个文件datastore-indexes.xml,其中包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<datastore-indexes
autoGenerate="true">
<datastore-index kind="Conference" ancestor="false">
<property name="city" direction="asc" />
<property name="topics" direction="asc" />
<property name="month" direction="asc" />
<property name="name" direction="asc" />
</datastore-index>
</datastore-indexes>
(但是,autoGenerate=“true”似乎没有效果)
2) 部署到appsot
这样,你在上面发布的查询对我有效。我也同意——课程的GAE版本似乎有所不同,因为有几个问题我很难解决(例如,我似乎没有本地数据存储,但每个本地主机执行都在访问我的appspot数据存储。)在添加索引之前是否插入了实体?您好@koma,谢谢您的回答。在添加索引之前插入实体是什么意思?我在数据库里已经有一些记录了。我必须删除它们,然后重新开始?谢谢你的回答。这就是问题所在。但是,Udacity的课程说它是一个复合索引,而且讲师是谷歌的开发人员。我想他们用的是更老的GAE版本。