ES 配置索引清理策略(入门)

2022/04/19

操作环境 Elasticsearch 6.8

Tips

创建索引生命周期

索引保留 7 天。

PUT _ilm/policy/cleanup-7d
{
  "policy": {
    "phases": {
      "delete": {
        "min_age": "7d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

由于我们的索引名称是添加了日期后缀,不要配置 rollover !否则执行流程上会出错。 【Kibana】索引生命周期策略错误 illegal_argument_exception: index.lifecycle.rollover_alias does not point to index

创建索引模版

将刚创建的生命周期策略和索引模版关联。

将 test-* 开头的索引按 clean-7d 的策略清理。

PUT _template/test
{
  "order": 10,
  "version": 1,
  "index_patterns": [
    "test-*"
  ],
  "settings": {
    "index.lifecycle.name": "cleanup-7d"
  }
}

更多参考