数据存储区索引不适用于JSON字符串的属性

时间:2019-10-15 23:52:10

标签: google-cloud-datastore gcloud

数据存储区中的以下查询返回预期的结果数:

SELECT timestamp from leadgenie_campaign_model_dev where campaign = "3667f39d-a3ff-4acb-b1ca-6f730bbc7989"

此查询由索引支持,该索引允许进行投影。

尽管存在索引,但此结果不会返回任何结果。 attrs是JSON字符串

SELECT timestamp, attrs from leadgenie_campaign_model_dev where campaign = "3667f39d-a3ff-4acb-b1ca-6f730bbc7989"

这是索引的规范:

indexes:

- kind: leadgenie_campaign_model_dev
  properties:
  - name: campaign
  - name: attrs
  - name: timestamp

- kind: leadgenie_campaign_model_dev
  properties:
  - name: campaign
  - name: timestamp
  - name: attrs

- kind: leadgenie_campaign_model_dev
  properties:
  - name: campaign
  - name: timestamp

2 个答案:

答案 0 :(得分:0)

您的attrs字段是否超过1500个字节?这是对要索引的字符串属性的限制。参见https://cloud.google.com/datastore/docs/concepts/limits

答案 1 :(得分:0)

解决方案是在专门为这些属性创建索引之后,将子属性包含在查询中。

SELECT timestamp, attrs.score, attrs.sz from leadgenie_campaign_model_dev where campaign = "3667f39d-a3ff-4acb-b1ca-6f730bbc7989"
google.api_core.exceptions.FailedPrecondition: 400 no matching index found. recommended index is:
- kind: leadgenie_campaign_model_dev
  properties:
  - name: campaign
  - name: attrs.score
  - name: attrs.sz
  - name: timestamp