【问题标题】:com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index foundcom.google.appengine.api.datastore.DatastoreNeedIndexException:找不到匹配的索引
【发布时间】:2014-03-24 02:11:19
【问题描述】:

当我使用 Objectify 部署我的 Google App Engine 服务器的 APP 时,我遇到了以下异常,尽管我已经配置了我的应用程序的所有索引。仍然不明白为什么我会收到此异常,由于此错误,我无法在此 Web 应用程序上执行任何操作。

生产服务器中的异常

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

datastore.indexes.xml

<?xml version="1.0" encoding="UTF-8"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind="M_COUNTRY" ancestor="false" source="auto">
 <property name="countryCode" direction="asc" />
 <property name="countryName" direction="asc" />
 <property name="active" direction="asc" />
</datastore-index>
<datastore-index kind="M_CITY" ancestor="false" source="auto">
 <property name="countryCode" direction="asc" />
 <property name="cityName" direction="asc" />
 <property name="cityCode" direction="asc" />
 <property name="active" direction="asc" />
</datastore-index>
<datastore-index kind="M_TAXI" ancestor="false" source="auto">
 <property name="cityName" direction="asc" />
 <property name="supplierUserName" direction="asc" />
 <property name="updatedOn" direction="asc" />
 <property name="active" direction="asc" />
 <property name="countryName" direction="asc" />
</datastore-index>
</datastore-indexes>

来自生产服务器的数据存储索引映像快照

【问题讨论】:

  • 似乎很清楚,您没有错误要求的精确索引。有什么让你感到困惑的?
  • @DanielRoseman 我很困惑,因为我已经明确定义了所有索引,那么为什么 appengine 会给出这个错误。
  • 但你没有!错误说它需要一个带有 cityName/updatedOn 的 M_TAXI 索引。你没有那个,你只有一个具有五个属性的那种索引。它不想要一个包含五个属性的索引,它想要一个包含两个属性的索引。
  • @DanielRoseman 能否请您给出一些示例代码的答案,因为我仍然很困惑。

标签: java google-app-engine objectify


【解决方案1】:

您必须将这些索引添加到您的datastore.indexes.xml

<datastore-index kind="M_TAXI" ancestor="false" source="manual">
    <property name="cityName" direction="asc"/>
    <property name="updatedOn" direction="asc"/>
</datastore-index>

由于 Appengine 数据存储是无模式的,因此您必须为不同的查询添加单独的索引。

请参考这个stackoverflow post

【讨论】:

    【解决方案2】:

    引发异常的查询无法使用现有的 M_TAXI。请尝试插入

    <datastore-index kind="M_TAXI" ancestor="false" source="manual">
        <property name="cityName" direction="asc"/>
        <property name="updatedOn" direction="asc"/>
    </datastore-index>
    

    在 结束标记之前和其他 M_TAXI 元素之后进入 datastore.indexes.xml,然后报告结果。

    【讨论】:

    • 如果需要多种类型的过滤器,是否需要添加多个
    • M_TAXI 种类的两个索引因其包含的字段而不同。所以是的,添加多个不同的条目。
    • 感谢您的帮助,现在它可以工作了,但过去 2 年我仍然没有得到我使用 appengine 的经验,我从未手动创建过任何 datastore-indexes.xml ,它由 Objectify @Index 注释自动处理。 appengine 或 objectify 配置是否有任何变化?
    • Datastore Indexes 文档说“开发服务器会在遇到无法使用现有索引执行的查询时自动向该文件添加建议”。它通常在后台发生,但您必须在开发服务器上执行每种类型的查询。此查询似乎未经测试就进入生产环境。
    猜你喜欢
    • 2019-01-14
    • 2018-11-23
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2015-06-30
    • 2015-06-30
    相关资源
    最近更新 更多