【问题标题】:DatastoreNeedIndexException in GAE even after indexes are being served即使在提供索引之后,GAE 中的 DatastoreNeedIndexException
【发布时间】:2013-09-26 06:17:17
【问题描述】:

在 GAE 上部署时出现以下错误,但是我的应用程序在本地服务器上运行良好。

com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
    <datastore-index kind="Order" ancestor="false" source="manual">
        <property name="employee" direction="asc"/>
        <property name="__key__" direction="asc"/>
        <property name="route" direction="asc"/>
    </datastore-index>

即使我需要的索引在 GAE 中提供服务

__key__ ?                                           Serving     6202    1 MByte
__key__ ? , route ?                                 Serving     6202    1 MByte
__key__ ? , route ? , __key__ ?                     Serving     6202    2 MBytes
customerName ? , __key__ ?                          Serving     6202    1 MByte
customerName ? , employee ? , oDate ? , __key__ ?   Serving     6202    2 MBytes
customerName ? , oDate ? , __key__ ?                Serving     6202    1 MByte
employee ? , __key__ ? , route ?                    Serving     6202    1 MByte
employee ? , __key__ ?                              Serving     6202    1 MByte
employee ? , oDate ? , __key__ ?                    Serving     6202    1 MByte
oDate ? , __key__ ?                                 Serving     6202    1 MByte
route ? , __key__ ?                                 Serving     6202    1 MByte

datastore-indexes.xml 的内容也会根据错误提示进行更新

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
    <!-- Used 7 times in query history -->
    <datastore-index kind="Order" ancestor="false" source="manual">
        <property name="employee" direction="asc"/>
        <property name="__key__" direction="asc"/>
        <property name="route" direction="asc"/>
    </datastore-index>

    <!-- Used 16 times in query history -->
    <datastore-index kind="LineItem" ancestor="false" source="manual">
        <property name="itemName" direction="asc" />
        <property name="orderID" direction="asc" />
        <property name="quantity" direction="asc" />
    </datastore-index>
</datastore-indexes>

这就是我要运行的查询。

Filter employeeFilter = new FilterPredicate("employee",FilterOperator.EQUAL, saleRepID);
Filter startTimeFilter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,FilterOperator.GREATER_THAN_OR_EQUAL, startOrderKey);
Filter endTimeFilter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,FilterOperator.LESS_THAN_OR_EQUAL, endOrderKey);

logger.warning("Creating a Final filter to find a uniquely visited routes by that employee in that particular time range");
Filter finalFilterForRoutes = CompositeFilterOperator.and(endTimeFilter, CompositeFilterOperator.and(employeeFilter,startTimeFilter));

logger.warning("Finding a uniquely visited routes by that employee on that particular day");
    QueryResultList<Entity> allRoutesVisited = datastore.prepare(new Query("Order").addProjection(
                                    new PropertyProjection("route",String.class)).setDistinct(true)
                                    .setFilter(finalFilterForRoutes))
                                    .asQueryResultList(FetchOptions.Builder.withDefaults());

【问题讨论】:

    标签: google-app-engine transactions google-cloud-datastore


    【解决方案1】:

    不幸的是,您在验证代码中遇到了一个错误(该错误已经修复,应该在 1.8.5 或 1.8.6 中出现)。实际上不支持该查询,因为它要求 '__key__' 和 'route' 都是索引排序顺序中的第一个值(这是不可能的)。如果要执行此查询,则必须在内存中收集 'route' 的不同值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-19
      • 2018-12-03
      • 2014-10-22
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      相关资源
      最近更新 更多