Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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 如何强制复合索引出现在谷歌云中?_Java_Google App Engine_Google Cloud Storage_Google Cloud Platform - Fatal编程技术网

Java 如何强制复合索引出现在谷歌云中?

Java 如何强制复合索引出现在谷歌云中?,java,google-app-engine,google-cloud-storage,google-cloud-platform,Java,Google App Engine,Google Cloud Storage,Google Cloud Platform,好的,在谷歌云中看到这张图片: 上面说“下面是此应用程序的复合索引。这些索引在应用程序的索引配置文件中进行管理。” 请参阅以下代码: public static long getPropertyMaxIDStronglyConsistent(String entityName, String propertyName, Key parentKey){ // Order alphabetically by property name: //Key

好的,在谷歌云中看到这张图片:

上面说“下面是此应用程序的复合索引。这些索引在应用程序的索引配置文件中进行管理。

请参阅以下代码:

public static long getPropertyMaxIDStronglyConsistent(String entityName, String propertyName, Key parentKey){
            // Order alphabetically by property name:
            //Key parentKey=KeyFactory.createKey(parentEntityName, parentName);
            Query q = new Query(entityName, parentKey).setAncestor(parentKey)
                            .addSort(propertyName, SortDirection.DESCENDING);

            //List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
            List<Entity> results = datastore.prepare(q)
                            .asList(FetchOptions.Builder.withLimit(5));        
            if(results.size()>0){
                Entity e=results.get(0);
                long maxID=(Long)e.getProperty(propertyName);


                return maxID;

            }
            else{
                return 0;
            }

    }

但它仍然不起作用

和中描述了应用程序引擎数据存储的索引(Java 7,但原则与Java 8相同)

  • 复合索引是由模型的多个属性组成的索引:例如,按model.name,然后按model.creationDate对模型进行排序的索引。复合索引用于需要按照查询描述的顺序访问数据存储记录的查询
  • 某些索引必须在datastore-indexes.xml文件中声明-
  • 服务状态表示索引已准备好使用;首次上载索引时,应用程序引擎必须生成索引,并且在生成索引之前,使用生成索引的查询将引发异常。因此,在部署需要它们的代码之前对它们进行修改是很有帮助的
  • 将你的应用程序配置为
    appengine数据存储的索引在和中进行了描述(Java7,但原理与Java8相同)

  • 复合索引是由模型的多个属性组成的索引:例如,按model.name,然后按model.creationDate对模型进行排序的索引。复合索引用于需要按照查询描述的顺序访问数据存储记录的查询
  • 某些索引必须在datastore-indexes.xml文件中声明-
  • 服务状态表示索引已准备好使用;首次上载索引时,应用程序引擎必须生成索引,并且在生成索引之前,使用生成索引的查询将引发异常。因此,在部署需要它们的代码之前对它们进行修改是很有帮助的
  • 将你的应用程序配置为
    我手动添加了索引&English Class索引出现了,但仍然不起作用。不知道为什么?显示您对问题中的索引所做的手动更改,以便我们查看它是否与查询匹配。您好,我更新了我的问题。它还没有起作用!不知道为什么?好的,我稍微更改了配置文件&它创建了一个新的索引。现在它起作用了,但问题是。如何删除旧索引?或者我们可以把旧的索引留在那里吗?如果我们把它放在那里,它会产生任何问题吗?你可以把它放在那里,除非你正在处理大量(数百万)的记录,否则它不会有任何危害。我手动添加了索引-“English Class”索引确实出现了,但仍然不起作用。不知道为什么?显示您对问题中的索引所做的手动更改,以便我们查看它是否与查询匹配。您好,我更新了我的问题。它还没有起作用!不知道为什么?好的,我稍微更改了配置文件&它创建了一个新的索引。现在它起作用了,但问题是。如何删除旧索引?或者我们可以把旧的索引留在那里吗?如果我们把它放在那里,它会产生任何问题吗?你可以把它放在那里,除非你正在处理大量(数百万)的记录,否则它不会有任何危害。
    <datastore-indexes autoGenerate="true">
        <datastore-index kind="EnglishClass" ancestor="true" source="auto">
            <property name="ClassNo" direction="desc"/>
    
        </datastore-index>
    </datastore-indexes>