【问题标题】:How to point elasticsearch alias to current index and removing the alias from old index from index template?如何将弹性搜索别名指向当前索引并从索引模板中的旧索引中删除别名?
【发布时间】:2020-01-18 07:39:30
【问题描述】:

在我们的应用程序中,我们每天都在创建弹性搜索索引,索引模式是 index-。 (例如 index-17-09-2019)。但是我们的应用程序通过指向当前索引的别名访问索引。现在使用索引附加和删除别名是通过 cron 作业完成的。是否可以通过索引模板来完成,因为我们正在避免 cron 工作。 我们可以通过索引模板将别名与索引附加,但我不确定我们是否可以将别名与旧索引分离并通过索引模板将其添加到新索引中。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这可以通过内置的索引生命周期管理 (ILM) 来完成。您的应用程序将向索引别名发送数据,而 ILM 将负责其余的工作。

    Here是描述如何做到的,但基本上你需要:

    1.创建 ILM 作业

    PUT /_ilm/policy/my_policy
    {
      "policy": {
        "phases": {
          "hot": {
            "actions": {
              "rollover": {
                "max_age": "1d"
              }
            }
          }
        }
      }
    }
    

    2。创建附加 ILM 策略的索引模板

    PUT _template/my_template
    {
      "index_patterns": ["test-*"], 
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 1,
        "index.lifecycle.name": "my_policy", 
        "index.lifecycle.rollover_alias": "test-alias" 
      }
    }
    

    3.通过创建初始化索引开始该过程

    PUT test-000001 
    {
      "aliases": {
        "test-alias":{
          "is_write_index": true 
        }
      }
    }
    

    这将帮助您每天处理新索引的创建,而无需外部 CRON 作业。您还可以稍后将您的政策扩展到例如delete old indices after 7 days after rollover

    希望对您有所帮助。

    【讨论】:

    • 是的。明白你的意思了。但是我的应用程序只从elasticsearch读取数据,而elasticsearch是通过基本上每天安排一次的logstash加载的,它每天将新数据从db加载到新索引。我的应用程序应该每天只从新索引中读取数据。所以我们创建了别名。那么如何处理这种情况呢?
    • 滚动操作将负责为新创建的索引创建写入别名,您可以通过查询 GET /alias_name/_alias 找到它。
    猜你喜欢
    • 2015-05-23
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 2021-03-06
    • 2014-12-08
    • 1970-01-01
    • 2018-07-17
    相关资源
    最近更新 更多