Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序引擎没有';t生成复合索引_Java_Google App Engine - Fatal编程技术网

Java 应用程序引擎没有';t生成复合索引

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

我正在学习Udacity的“用Java开发可伸缩应用”教程,并尝试通过多个属性创建查询,但它不起作用

以下是Api方法:

@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
    为空,因为在您的情况下不需要复合索引
  • 简单索引是在声明后自动在每个实体保存/更新上构建的。因此,如果数据库中已有一些实体,并且声明了一个新索引,则现有实体将不会更新
  • 对于自定义索引,自动生成策略正好相反:声明自定义索引后,DB将遍历所有现有实体并更新自定义索引。这可能需要一些时间,当索引准备就绪时,您可以在GAE管理控制台中进行检查

  • 我也在同样的道路上工作,在这一点上也很挣扎。不管我做什么,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版本。