如何通过REST API创建Google数据存储区复合索引?

时间:2015-07-23 03:01:28

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

我正在尝试更改结果的顺序,但我一直收到错误You need an index to execute this query.

在我的控制台中,我没有说任何索引存在,但我将大多数索引选项设置为true。

我知道在Java中,我可以创建与多个属性相关的索引,无论是升序还是降序,我如何使用REST API执行此操作?

在Google数据存储区REST API docs之后,我的实体创建如下:

{
  "mode": "TRANSACTIONAL",
  "transaction": "Eb2wksWfYDjkGkkABRmGMQ_vKGijwNwm-tbxAbUPRt8N2RaUCynjSbGT7jFQw3pgaDCT7U0drs3RTPLSIN8TQikdqkdl7pLm2rkMqORmKlO_I_dp",
  "mutation": {
    "insertAutoId": [
      {
        "key": {
          "path": [
            {
              "kind": "Attendance"
            }
          ]
        },
        "properties": {
          "section": {
            "indexed": true,
            "stringValue": "Venturers"
          },
          "date": {
            "dateTimeValue": "2015-01-16T00:00:00+00:00",
            "indexed": true
          },
          "attendee": {
            "indexed": true,
            "keyValue": {
              "path": [
                {
                  "id": "5659313586569216",
                  "kind": "Attendee"
                }
              ]
            }
          },
          "presence": {
            "indexed": false,
            "integerValue": 0
          }
        }
      }
    ]
  }
}

我试图像这样查询:

{
  "gqlQuery": {
    "allowLiteral": true,
    "queryString": "SELECT * FROM Attendance WHERE section = @section ORDER BY date ASC",
    "nameArgs": [
      {
        "name": "section",
        "value": {
          "stringValue": "Venturers"
        }
      }
    ]
  }
}

我收到了这个错误:

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

1 个答案:

答案 0 :(得分:0)

供将来参考:

您无法直接通过REST API创建复合索引。你必须通过php app引擎。

How to build datastore indexes (PHP GAE)