所需的复合索引不存在,但在index.yaml中定义

问题描述 投票:2回答:1

我有一些物联网设备将一些数据发送到Google Cloud Datastore。

数据存储区在数据存储区模式下设置为Cloud Firestore。

每行都有以下字段:

  • 名称/ ID
  • 目前的温度
  • 数据
  • 设备编号
  • 事件
  • gc_pub_sub_id
  • published_at
  • target_temperature

这些都属于ParticleEvent类型。

我希望运行以下查询; select current_temperature, target_temperature from ParticleEvent where device_id = ‘abc123’ order by published_at desc

我尝试运行该查询时收到以下错误:

GQL查询错误:您的数据存储区没有此查询所需的复合索引(开发人员提供)。

所以我设置了一个index.yaml文件,其中包含以下内容:

indexes:

- kind: ParticleEvent
  properties:
  - name: data
  - name: device_id
  - name: published_at
    direction: desc

- kind: ParticleEvent
  properties:
  - name: current_temperature
  - name: target_temperature
  - name: device_id
  - name: published_at
    direction: desc

我使用gcloud工具将此成功发送到数据存储区,我可以在索引选项卡中看到两个索引。

但是,当我尝试运行查询时,仍然会出现上述错误。

我需要添加/更改索引才能使此查询生效?

google-cloud-platform google-cloud-datastore
1个回答
2
投票

虽然在评论中我只是建议select *(这是最好的方式,我认为)

有一种方法可以使您的查询工作。

- kind: ParticleEvent
  properties:
  - name: device_id
  - name: published_at
    direction: desc
  - name: current_temperature
  - name: target_temperature

原因是select最后完成,因此你需要current_temperaturetarget_temperature的指数在较低的水平。


为什么我不建议这样做是因为,当您的数据增长时,您需要更多的索引组合,因为select特定列。您的索引大小将呈指数级增长。

但是,如果您确定只使用一次并始终查询这样的数据,那么请随意索引它。

或者,如果您的计算机和Google云之间的连接带宽非常小,那么下载更多数据会导致延迟。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.