【问题标题】:Google Cloud Datastore runQuery returning 412 "no matching index found"Google Cloud Datastore runQuery 返回 412“找不到匹配的索引”
【发布时间】:2013-07-02 16:58:30
【问题描述】:

** 更新 **

感谢 Alfred Fuller 指出我需要为此查询创建手动索引。

不幸的是,使用来自 .NET 应用程序的 JSON API,似乎没有官方支持的方式。事实上,官方似乎根本没有办法从 App Engine 之外的应用程序中执行此操作,这很奇怪,因为 Cloud Datastore API 旨在允许访问 App Engine 之外的数据存储区。

我能找到的最接近的 hack 是 POST the index definition using RPChttp://appengine.google.com/api/datastore/index/add。有人可以给我关于如何准确执行此操作的原始规范(即 URL 参数、正文应该是什么样子等),也许使用 Fiddler 来检查 appcfg.cmd 进行的调用?

** 原始问题 **

根据docs,“查询可以组合不同属性的相等 (EQUAL) 过滤器,以及单个属性上的一个或多个不等过滤器”。

但是,此查询失败:

{
 "query": {
  "kinds": [
   {
    "name": "CodeProse.Pogo.Tests.TestPerson"
   }
  ],
  "filter": {
   "compositeFilter": {
    "operator": "and",
    "filters": [
     {
      "propertyFilter": {
       "operator": "equal",
       "property": {
        "name": "DepartmentCode"
       },
       "value": {
        "integerValue": "123"
       }
      }
     },
     {
      "propertyFilter": {
       "operator": "greaterThan",
       "property": {
        "name": "HourlyRate"
       },
       "value": {
        "doubleValue": 50
       }
      }
     },
     {
      "propertyFilter": {
       "operator": "lessThan",
       "property": {
        "name": "HourlyRate"
       },
       "value": {
        "doubleValue": 100
       }
      }
     }
    ]
   }
  }
 }
}

回复如下:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "FAILED_PRECONDITION",
    "message": "no matching index found.",
    "locationType": "header",
    "location": "If-Match"
   }
  ],
  "code": 412,
  "message": "no matching index found."
 }
}

【问题讨论】:

    标签: google-cloud-datastore


    【解决方案1】:

    JSON API 尚不支持本地索引生成,但我们记录了一个过程,您可以按照该过程在https://developers.google.com/datastore/docs/tools/indexconfig#Datastore_Manual_index_configuration 生成索引的 xml 定义

    请试一试,如果它不起作用,请告诉我们。

    这是一个临时解决方案,我们希望尽快替换为自动本地索引生成。

    【讨论】:

    • Max - 谢谢,我看到了。生成 XML 索引定义文件没有问题。问题是 - 我如何将它上传到服务器?我没有 Java 或 Python App Engine 应用程序...
    • 另外,该文档的下一部分提到了一个 GCD 命令行工具,看起来我可以用来更新服务器上的索引。我在哪里可以找到该工具?
    • @codeprose-sam 请参阅developers.google.com/datastore/docs/tools/…,了解如何运行 gcd 来更新索引。您可以从这里下载:developers.google.com/datastore/docs/downloads#tools
    【解决方案2】:

    错误“找不到匹配的索引”。表示需要添加索引才能使查询正常工作。请参阅auto index generation documentation

    在这种情况下,您需要一个具有属性 DepartmentCode 和 HourlyRate(按此顺序)的索引。

    【讨论】:

    • 谢谢阿尔弗雷德!请参阅我对问题的更新。不幸的是,我使用的是 JSON API,而没有使用 App Engine SDK(这可以让我轻松地包含 index def 文件)。
    【解决方案3】:

    对于gcloud-node,我用这三个链接修复了它:

    还有最重要的链接:

    如上一个链接中所述,索引是通过将查询的结果集存储在索引中来允许复杂查询运行得更快的原因。当您收到no matching index found 时,这意味着您尝试运行涉及orderfilter 的复杂查询。因此,为了使您的查询正常工作,您需要通过手动创建配置文件来在 google 数据存储索引上创建索引,以定义代表您尝试运行的查询的索引。解决方法如下:

    1. 按照 python conf 文件的指令https://cloud.google.com/appengine/docs/python/config/indexconfig#Python_About_index_yaml 或从https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/system-test/data/index.yaml 中的gcloud-node 测试中获取灵感,在您的应用程序目录中的一个名为例如indexes 的文件夹中创建一个index.yaml 文件李>
    2. 使用以下命令从配置文件创建索引: gcloud preview datastore create-indexes indexes/index.yaml https://cloud.google.com/sdk/gcloud/reference/preview/datastore/create-indexes
    3. 等待索引在 Cloud Datastore/Indexes 中的开发者控制台上服务,一旦索引建立,界面应显示“服务中”
    4. 一旦它为您的查询提供服务,它应该可以工作

    例如对于这个查询:

     var q = ds.createQuery('project')
      .filter('tags =', category)
      .order('-date');
    

    index.yaml 看起来像:

    indexes:
    
    - kind: project
      ancestor: no
      properties:
      - name: tags
      - name: date
        direction: desc
    

    【讨论】:

      【解决方案4】:

      尽量不要对结果进行排序。删除 orderby() 后,它对我有用。

      【讨论】:

        猜你喜欢
        • 2021-10-28
        • 1970-01-01
        • 2018-11-28
        • 2016-04-05
        • 1970-01-01
        • 2021-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多