Google Cloud Datastore runQuery返回412“找不到匹配的索引” [英] Google Cloud Datastore runQuery returning 412 "no matching index found"

查看:155
本文介绍了Google Cloud Datastore runQuery返回412“找不到匹配的索引”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

** UPDATE **



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



不幸的是,使用来自.NET应用程序的JSON API,似乎没有官方支持的方式。事实上,从App Engine之外的应用程序中看不出是这样做的一种方式,这很奇怪,因为Cloud Datastore API旨在允许访问App Engine之外的数据存储。



我能找到的最接近的黑客是使用RPC发布索引定义 http: //appengine.google.com/api/datastore/index/add 。有人可以给我原始的规范,如何完全做到这一点(即URL参数,身体应该是什么样的,等等),也许使用Fiddler检查appcfg.cmd所做的调用?



**原始问题**



根据 docs ,查询可以将不同属性的平等(EQUAL)过滤器和单个属性上的一个或多个不等式过滤器组合在一起。 b
$ b

然而,这个查询失败:

  {
query:{
种类:[
{
name:CodeProse.Pogo.Tests.TestPerson
}
],
过滤器: {
compositeFilter:{
operator:and,
filters:[
{
propertyFilter:{
运算符:相等,
属性:{
name:DepartmentCode
},
值: {
integerValue:123
}
}
},
{
propertyFilter:{
operator: bigThan,
property:{
name:HourlyRate
},
value:{
doubleValue:50


$ propertyFilter $ {
operator:lessThan,
property:{




name:HourlyRate
},
value:{
doubleValue:100
}
}
}





code


以下回应:

  {
错误:{
错误: [
{
domain:global,
reason:FAILED_PRECONDITION,
message:找不到匹配的索引,
locationType:header,
location:If-Match
}
],
code:412,
messag e:找不到匹配的索引。
}
}


解决方案

错误找不到匹配的索引。表示需要添加索引才能使查询生效。请参阅自动索引生成文档



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


** UPDATE **

Thanks to Alfred Fuller for pointing out that I need to create a manual index for this query.

Unfortunately, using the JSON API, from a .NET application, there does not appear to be an officially supported way of doing so. In fact, there does not officially appear to be a way to do this at all from an app outside of App Engine, which is strange since the Cloud Datastore API was designed to allow access to the Datastore outside of App Engine.

The closest hack I could find was to POST the index definition using RPC to http://appengine.google.com/api/datastore/index/add. Can someone give me the raw spec for how to do this exactly (i.e. URL parameters, what exactly should the body look like, etc), perhaps using Fiddler to inspect the call made by appcfg.cmd?

** ORIGINAL QUESTION **

According to the docs, "a query can combine equality (EQUAL) filters for different properties, along with one or more inequality filters on a single property".

However, this query fails:

{
 "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
       }
      }
     }
    ]
   }
  }
 }
}

with the following response:

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

解决方案

The error "no matching index found." indicates that an index needs to be added for the query to work. See the auto index generation documentation.

In this case you need an index with the properties DepartmentCode and HourlyRate (in that order).

这篇关于Google Cloud Datastore runQuery返回412“找不到匹配的索引”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆