** 更新 **
感谢 Alfred Fuller 指出我需要为此查询创建手动索引。
不幸的是,从 .NET 应用程序使用 JSON API 似乎没有官方支持的方法。事实上,官方似乎根本没有一种方法可以从 App Engine 之外的应用程序执行此操作,这很奇怪,因为 Cloud Datastore API 的设计目的是允许访问 App Engine 之外的数据存储区。
我能找到的最接近的黑客是使用 RPC POST 索引定义 http://rahulswackyworld.blogspot.com/2010/03/dynamic-indexes-with-google-app-engine.html to http://appengine.google.com/api/datastore/index/add http://appengine.google.com/api/datastore/index/add。有人可以给我如何准确执行此操作的原始规范(即 URL 参数、正文应该是什么样子等),也许使用 Fiddler 来检查 appcfg.cmd 进行的调用?
** 原始问题 **
根据docs https://developers.google.com/datastore/docs/concepts/queries#Datastore_Restrictions_on_queries,“查询可以组合不同属性的等式 (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."
}
}