Kibana 为什么自动删除索引策略在ElasticSearch中不起作用?

vfhzx4xs  于 2022-12-09  发布在  Kibana
关注(0)|答案(2)|浏览(399)

我在Kibana中创建了一个索引策略,以删除超过7天的索引顺序。以下是配置:

我有使用此策略的索引,但没有一个被删除。下面是其中一个索引设置配置。它已经指定了要使用的策略:metrics-log-retention .有什么我错过的吗?

{
  "aws-logs-2022-02-01" : {
    "settings" : {
      "index" : {
        "lifecycle" : {
          "name" : "metrics-log-retention"
        },
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "aws-logs-2022-02-01",
        "creation_date" : "1643673636747",
        "priority" : "100",
        "number_of_replicas" : "1",
        "uuid" : "lLmO753nRpuw6bauKIJI2Q",
        "version" : {
          "created" : "7150299"
        }
      }
    }
  }
}

下面是热阶段。我已经禁用了热下的所有选项,如下面的截图所示。但它仍然不工作。

以下是索引策略的原始数据:

{
  "metrics-log-retention" : {
    "version" : 4,
    "modified_date" : "2022-02-10T22:24:14.492Z",
    "policy" : {
      "phases" : {
        "hot" : {
          "min_age" : "0ms",
          "actions" : {
            "rollover" : {
              "max_size" : "50gb",
              "max_primary_shard_size" : "50gb",
              "max_age" : "1d"
            }
          }
        },
        "delete" : {
          "min_age" : "6d",
          "actions" : {
            "delete" : {
              "delete_searchable_snapshot" : true
            }
          }
        }
      }
    },
    "in_use_by" : {
      "indices" : [
        "aws-logs-2022-02-01",
        "aws-logs-2022-02-04",
        "aws-logs-2022-02-05",
        "aws-logs-2022-02-02",
        "aws-logs-2022-02-03",
        "aws-metrics-2022-02-01",
        "aws-metrics-2022-02-07",
        "aws-logs-2022-02-08",
        "aws-metrics-2022-02-06",
        "aws-logs-2022-02-09",
        "aws-logs-2022-02-06",
        "aws-metrics-2022-02-09",
        "aws-logs-2022-02-07",
        "aws-metrics-2022-02-08",
        "aws-metrics-2022-02-03",
        "aws-metrics-2022-02-02",
        "aws-metrics-2022-02-05",
        "aws-metrics-2022-02-04",
        "aws-logs-2022-02-11",
        "aws-logs-2022-02-12",
        "aws-logs-2022-02-10",
        "aws-logs-2022-02-13",
        "aws-metrics-2022-02-10",
        "aws-metrics-2022-02-12",
        "aws-metrics-2022-02-11",
        "aws-metrics-2022-02-13"
      ],
      "data_streams" : [ ],
      "composable_templates" : [ ]
    }
  }
}
mo49yndu

mo49yndu1#

正如您在热阶段高级设置中所看到的,默认翻转设置为30天或50GB,因此您的索引将在热阶段停留30天,除非它们之前增长超过50GB。
一旦索引脱离热阶段,它将进入删除阶段,如果您将鼠标悬停在(i)图标上,您可以看到7天是在从热阶段滚动之后计算的。

因此,如果您确实希望在7天后删除索引,则需要:
1.将热阶段配置得更短(例如6天)
1.将删除阶段配置为在滚动1天后启动
这样,索引将被创建并在热阶段停留六天,然后在一天后被删除。

cwtwac6a

cwtwac6a2#

只需将其添加到ES主机上的crontab,它将自动删除旧索引

0 7 * * * curl -u LOGIN:PASSWORD -XDELETE http://localhost:9200/aws-logs-$(date --date="7 days ago" +"%Y.%m.%d")

相关问题