如何强制复合索引出现在 Google Cloud 中?

How to force composite indexes to appear in Google Cloud?

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

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

并查看以下代码:

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;
            }

    }

假设我们是运行这个function1getPropertyMaxIDStronglyConsistent("EnglishClass", "ClassNo", KeyFactory.createKey("EnglishClassParent", "EnglishClassParentName")).

我发现,如果“EnglishClass”类型没有出现在 [=43] 中,function1 将无法工作=]Indexes Table 状态为“serving”。

我不知道我做了什么,但是在我挣扎了几个小时之后突然出现了索引“EnglishClass”。当“EnglishClass”以“serving”状态出现时,应用程序可以正常运行,没有任何问题。

我的问题是

什么是复合索引?

为什么没有在运行 function1之后立即出现?

"serving"状态是什么意思?

如何强制复合索引出现在Google Cloud中?

额外: 在 datastore-indexes-auto.xml 我有

<datastore-indexes autoGenerate="true">
    <datastore-index kind="EnglishClass" ancestor="true" source="auto">
        <property name="ClassNo" direction="desc"/>

    </datastore-index>
</datastore-indexes>

但是还是不行

App Engine 数据存储区的索引在 these docs and these docs(Java 7 中进行了描述,但原理与 Java 8 相同)。

  1. 复合索引是一种包含多个 属性 模型的索引:例如,按 Model.name 然后 Model.creationDate 对模型进行排序的索引。需要按查询描述的顺序访问数据存储记录的查询使用复合索引。
  2. 有些索引必须在数据存储中声明-indexes.xml 文件 - see here
  3. 服务状态表示索引可以使用;首次上传索引时,App Engine 必须构建索引,在构建索引之前,使用构建索引的查询将抛出异常。因此,在部署需要它们的代码之前,update indexes 可能会有所帮助。
  4. 将您的应用配置为 automatically configure indexes