AWS elasticsearch 禁用所有索引的复制

AWS elasticsearch disable replication of all indices

我正在使用单节点 AWS ES 集群。目前,它的健康状态显示黄色,这是显而易见的,因为没有其他节点可供 Amazon ES 分配副本。我想将所有当前和即将发布的索引的复制设置为 0。我以这种模式创建了索引:

app-one-2021.02.10
app-two-2021.01.11
so on...

这些索引目前 number_of_replicas 设置为 1。要禁用所有索引的复制,我在索引模式中抛出一个 PUT 请求:

PUT /app-one-*/_settings
{
 "index" : {
  "number_of_replicas":0
 }
}

由于我在这里使用了通配符,所以它应该在所有匹配的索引中将 number_of_replicas 设置为 0,这是成功的。

但如果将来创建任何新索引,假设是 app-one-2021.03.10。然后 number_of_replicas 在此索引中再次设置为 1。

每次我必须 运行 一个 PUT 请求以将 number_of_replicas 设置为 0,这很乏味。为什么即使我在 PUT 请求中使用通配符 (*),新索引也不会自动将 number_of_replicas 变为 0

有什么办法可以完全把replication(number_of_replicas to 0)设置为0,不管是新索引还是旧索引。我怎样才能做到这一点?

是的,方法是定义索引模板。

在 Elasticsearch v7.8 之前,您只能使用 _template API (see docs)。例如,在您的情况下,您可以创建一个匹配所有 app-* 索引的模板:

PUT _template/app_settings
{
  "index_patterns": ["app-*"],
  "settings": {
    "number_of_replicas": 0
  }
}

从 Elasticsearch v7.8 开始,旧的 API 仍然受支持但已弃用,您可以使用 _index_template API 代替 (see docs)。

PUT _index_template/app_settings
{
  "index_patterns": ["app-*"],
  "template": {
    "settings": {
      "number_of_replicas": 0
    }
  }
}

更新:为_template_index_template添加代码片段API.