首页 > 解决方案 > 删除 Google Cloud Datastore 索引

问题描述

我添加了几个月的 Google Datastore 索引很少。今天我又加了一个。几分钟后,我发现这不是我必须创建的正确索引。

我这样称呼:

$ gcloud datastore indexes list
---
ancestor: NONE
indexId: XXX1
kind: ThisIsKindName
projectId: GCP-PROJ-ID
properties:
- direction: ASCENDING
  name: QueueName
- direction: ASCENDING
  name: ExecutionLength
state: READY
---
ancestor: NONE
indexId: XXX2
kind: ThisIsKindName
projectId: GCP-PROJ-ID
properties:
- direction: ASCENDING
  name: labels.application
- direction: DESCENDING
  name: ExecutionLength
state: READY
---
...

并找到要删除的索引 (ID= XXX2)。

我找到了清理命令描述,但我不清楚。此功能要求提供index.yaml文件。

应该在这个文件中找到什么?

  1. 要保留的索引列表。该文件中不存在的所有索引都将被删除。
  2. 要删除的索引列表。

如果您的答案是 1(要保留的索引列表)-我如何yaml从现有索引生成文件?它是必需的,因为我在本地没有那些索引定义。需要类似的东西:

gcloud datastore indexes list --export=yaml

标签: google-cloud-platformgoogle-cloud-datastore

解决方案


根据公共文档,该命令将删除 index.yaml 文件中未包含的所有索引。因此,在 index.yaml 文件中确保只包含您正在使用的索引。

据我所知,似乎没有特别的方法可以生成新的 index.yaml 文件,但是,最好的做法似乎是尝试导出所用命令的输出:

    gcloud datastore indexes list > index.yaml

(更改命令以满足 CLI 的需求)

并继续使用提供的示例作为指导对其进行适当的格式化。


推荐阅读