所需的复合索引不存在,但已在 index.yaml 中定义
Composite index required does not exist, yet defined in index.yaml
我有一些物联网设备正在将一些数据发送到 Google 云数据存储。
Datastore 在 Datastore 模式下设置为 Cloud Firestore。
每一行都有以下字段:
- Name/ID
- current_temperature
- 数据
- device_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 query error: Your Datastore does not have the composite index (developer-supplied) required for this query.
所以我设置了一个包含以下内容的 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
工具将其成功发送到数据存储区,我可以在索引选项卡中看到这两个索引。
然而,当我尝试 运行 查询时,仍然出现上述错误。
我需要 add/change 我的索引什么才能使此查询正常工作?
尽管在评论中我只是建议 select *
(我认为这是最好的方法)
有一种方法可以使您的查询有效。
- kind: ParticleEvent
properties:
- name: device_id
- name: published_at
direction: desc
- name: current_temperature
- name: target_temperature
之所以select
在最后完成,所以需要current_temperature
和target_temperature
的索引在下层
为什么我不建议这种方式是因为,当您的数据增长并且您需要更多索引组合时 只是因为 select
特定列。您的索引大小将呈指数级增长。
但是假设您确定只使用一次并且总是这样查询数据,那么请随时为它建立索引。
或者,如果您的计算机与 google 云之间的连接带宽非常小,以至于下载更多数据会导致延迟。
我有一些物联网设备正在将一些数据发送到 Google 云数据存储。
Datastore 在 Datastore 模式下设置为 Cloud Firestore。
每一行都有以下字段:
- Name/ID
- current_temperature
- 数据
- device_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 query error: Your Datastore does not have the composite index (developer-supplied) required for this query.
所以我设置了一个包含以下内容的 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
工具将其成功发送到数据存储区,我可以在索引选项卡中看到这两个索引。
然而,当我尝试 运行 查询时,仍然出现上述错误。
我需要 add/change 我的索引什么才能使此查询正常工作?
尽管在评论中我只是建议 select *
(我认为这是最好的方法)
有一种方法可以使您的查询有效。
- kind: ParticleEvent
properties:
- name: device_id
- name: published_at
direction: desc
- name: current_temperature
- name: target_temperature
之所以select
在最后完成,所以需要current_temperature
和target_temperature
的索引在下层
为什么我不建议这种方式是因为,当您的数据增长并且您需要更多索引组合时 只是因为 select
特定列。您的索引大小将呈指数级增长。
但是假设您确定只使用一次并且总是这样查询数据,那么请随时为它建立索引。
或者,如果您的计算机与 google 云之间的连接带宽非常小,以至于下载更多数据会导致延迟。