ElasticSearch-滚动索引的别名自动更新 [英] ElasticSearch - alias auto update for rolling index

查看:851
本文介绍了ElasticSearch-滚动索引的别名自动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了以下滚动索引:

I have the following rolling index defined:

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "elmah_*",
        "alias": "elmah_all"
      }
    }
  ]
}

今天效果很好,它把我所有的现有月度滚动指标。问题在于,当索引滚动到新的月份时,它会自动生成新索引 elmah_2016_06 ,但是我的别名未选择该新索引。每个月我都需要运行以下命令来更新别名:

That works great today, it picked up all my existing monthly rolling indexes. The problem is that when the index rolls over to a new month it automatically generates the new index of elmah_2016_06, but my alias doesn't pick up this new index. Each month I need to update my alias by running this:

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "elmah_2016-06",
        "alias": "elmah_all"
      }
    }
  ]
}

有没有办法让ES来选择

Is there any way to have ES pick this up automatically?

推荐答案

是的,您可以使用模板。

Yep, you can use a template.

PUT /_template/my_elmah_template
{
  "template" : "elmah_*",
  "alias" : {
    "elmah_all" : { }
  }
}

空对象是必不可少的,因为JSON期望 field:值

The empty object is a necessary evil because JSON expects field : value.

只要匹配的索引(基于模板参数)创建,然后它将自动对其应用模板。在这种情况下,模板唯一要做的就是为其添加别名。

Whenever a matching index (based on the template parameter) is created, then it will automatically apply the template to it. In this case, the only thing that the template is doing is to add an alias to it.

您还可以使用模板来设置设置和映射

这篇关于ElasticSearch-滚动索引的别名自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆