【问题标题】:How deleting old indices after x days for multiple indices pattern elasticsearch?如何在 x 天后删除多个索引模式弹性搜索的旧索引?
【发布时间】:2021-03-06 02:29:51
【问题描述】:

我正在使用 Elasticsearch 来存储微服务日志。 所有微服务都以通用模式登录,并由 Fluentd 收集的日志收集并发送到索引名称模式,如log-${serviceName}-%Y.%m.%d

我为 log-- 定义了一个索引模板,并创建了一个 ILM 策略以在 2 天后将索引翻转到删除阶段并在 4 天后将其删除。并使用my-log-alias 将 ILM 策略连接到索引模板。

所以我需要这样的东西: each day, there are for example 10 active indices that log documents written to them. and after 2 days these indices all go to the delete phase.

  1. 我可以为我的所有服务使用一个索引模板和一个 ILM 策略吗?
  2. 我在 elasticsearch 索引模板和策略上的设置有什么问题?
  3. 我是否以正确的方式使用此功能?

感谢您的阅读。

索引模板:

{
  "order": 0,
  "index_patterns": [
    "log-*-*"
  ],
  "settings": {
    "index": {
      "lifecycle": {
        "name": "my-log",
        "rollover_alias": "my-log-alias"
      },
      "number_of_replicas": "1"
    }
  },
  "aliases": {
    "sb-log": {}
  },
  "mappings": {
    "_doc": {
      "properties": {
        "level": {
          "ignore_above": 256,
          "type": "keyword"
        },
        "message": {
          "type": "text"
        }
      }
    }
  }
}

ilm 政策

{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "rollover": {
            "max_age": "2d",
            "max_size": "50gb"
          },
          "set_priority": {
            "priority": 100
          }
        }
      },
      "delete": {
        "min_age": "4d",
        "actions": {
          "delete": {
            "delete_searchable_snapshot": true
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-indices


    【解决方案1】:
    1. 我可以为我的所有服务使用一个索引模板和一个 ILM 策略吗?

    是的,你可以。

    1. 我在 elasticsearch 索引模板和策略上的设置有什么问题?

    根据您的定义,索引会在 2 天(或 50gb)后滚动更新,并在滚动操作 4 天后被删除。

    【讨论】:

    猜你喜欢
    • 2015-05-23
    • 2016-01-30
    • 2018-10-04
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多