我的应用程序当前定义了所需的所有最佳索引。但慢慢地我开始遭受爆炸索引问题的困扰,所以我想改变我的策略并开始使用“zig-zag”合并,如此处所述。
我的实体Contact
有 3 个排序顺序:
lastModified
ASCfullNameUpperCase
ASC + DESC
它有 4 个过滤器:
contactProfile
contactStatus
contactType
searchFields
(模拟'startsWith...'的不等式查询)
searchFields 是一个特例,因为我用它来模拟像这样的“startswith”
query = query.filter("searchFields >= ", criteria.getSearchString().toUpperCase());
query = query.filter("searchFields <= ", criteria.getSearchString().toUpperCase() + "\ufffd");
按照文章中的解释,我需要定义
(number of filters + 1) * (number of orders) = 5 * 3 = 15.
- 我的主要问题!:
下面的新定义似乎在开发服务器上工作,但不是第一次。第一次应该进行 zigzag 合并的新组合时,开发服务器仍然会抛出 DatastoreNeedIndexException。第二次重复相同的查询,查询运行并返回预期的结果。在对结果进行分页时也会发生这种情况。第一次查询下一页时,抛出异常。重复作品。有人也见过这种行为吗?这是开发服务器问题还是我遗漏了什么?还是这个最初不完整的索引构建可能......例如,当我第一次组合这些过滤器时,开发服务器抱怨它作为索引丢失:
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="contactProfile" direction="asc"/>
<property name="status" direction="asc"/>
<property name="fullNameUpperCase" direction="desc"/>
</datastore-index>
以下是实体 Contact 的新索引定义:
<!-- SORT ORDERS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="lastModified" direction="desc" />
</datastore-index>
<!-- FILTER: SEARCHFIELDS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="asc" />
<property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="desc" />
<property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="lastModified" direction="desc" />
<property name="searchFields" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTSTATUS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="asc" />
<property name="status" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="desc" />
<property name="status" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="lastModified" direction="desc" />
<property name="status" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTTYPE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="asc" />
<property name="contactType" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="desc" />
<property name="contactType" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="lastModified" direction="desc" />
<property name="contactType" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTPROFILE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="asc" />
<property name="contactProfile" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="fullNameUpperCase" direction="desc" />
<property name="contactProfile" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
<property name="lastModified" direction="desc" />
<property name="contactProfile" direction="asc" />
</datastore-index>