【问题标题】:How to create google datastore composite indices via REST API?如何通过 REST API 创建谷歌数据存储复合索引?
【发布时间】:2015-07-23 03:01:28
【问题描述】:

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

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

我知道在 Java 中,我可以创建与多个属性相关的索引,无论是升序还是降序,我如何使用 REST API 来做到这一点?

按照 Google Datastore 的 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."
  }
}

【问题讨论】:

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


    【解决方案1】:

    供将来参考:

    您不能直接通过 REST API 创建复合索引。你必须通过php应用引擎。

    How to build datastore indexes (PHP GAE)

    【讨论】:

    • 你怎么知道他的appengine是php的?
    • @ZigMandel 因为还有谁知道他在用什么? :)
    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 2014-06-25
    • 2020-06-24
    • 2018-10-14
    • 2023-03-12
    相关资源
    最近更新 更多