【问题标题】:How to delete indexes automatically regularly in ES?ES中如何定期自动删除索引?
【发布时间】:2016-11-05 22:11:17
【问题描述】:

我正在使用 ES 2.3.3 和 Logstash 2.3.3。我一直在使用 Logstash 发送数据并将它们映射到 ES 中进行索引,即 logstash-{Date}。我只想保留最近 1 年的文件。任何超过一年的索引都应删除。我之前使用的是 3.5.1。我删除索引的方法是每天输入一个命令。

curator --host 10.0.0.2 delete indices --older-than 30 --time-unit days \
   --timestring '%Y.%m.%d' 

最近,我将curator 3.5.1升级到curator 4。但是,即使我已经阅读了https://www.elastic.co/guide/en/elasticsearch/client/curator/current/command-line.html中的示例,我也找不到curator的存储位置因此,我想知道配置文件在哪里是以及为什么会缺少action_file?这是否意味着我需要创建一个新的 .curator 目录以及我自己的 curator.yml 和 action.yml 文件?

在我创建了 action.yml 文件之后,我是否应该按照 https://www.elastic.co/guide/en/elasticsearch/client/curator/current/examples.html#ex_delete_indices 并将这部分添加到我的 action.yml 文件中,以便在一年内删除 logstash 索引?

谢谢

【问题讨论】:

  • 您能否提供更多关于您要完成的任务的信息?你的指数是什么样的?它们是时间序列吗?他们有常规的命名模式吗?您在什么操作环境(操作系统、Elasticsearch 版本等)下工作?
  • 是的,我已经更新了我的问题,我希望它可以更好地了解我的需求。谢谢。
  • 你可以参考这个链接stackoverflow.com/a/42268400/2874585

标签: elasticsearch elasticsearch-curator


【解决方案1】:

配置文件可以在任何地方,只要您使用 --config 标志启动 Curator:

curator --config /path/to/curator_config.yml

但是,如果您在将运行 Curator 的用户的主目录中创建一个 .curator 路径(表面上是通过 cron),它将在那里寻找一个名为 curator.yml 的文件,例如/home/username/.curator/curator.yml

在该位置正确配置该文件后,Curator 将不需要--config 标志。

Curator 只是使用最后一个参数作为动作文件:

» curator --help
Usage: curator [OPTIONS] ACTION_FILE

  Curator for Elasticsearch indices.

  See http://elastic.co/guide/en/elasticsearch/client/curator/current

Options:
  --config PATH  Path to configuration file. Default: ~/.curator/curator.yml
  --dry-run      Do not perform any changes.
  --version      Show the version and exit.
  --help         Show this message and exit.

使用$HOME/.curator/curator.yml 中的默认配置文件运行 Curator 的示例如下:

curator /path/to/actionfile.yml

并使用自定义配置文件:

curator --config /path/to/curator_config.yml /path/to/actionfile.yml

遵循操作文件示例是一个很好的起点。随意尝试新配置,但请务必使用--dry-run 标志,以防止在测试时采取任何行动。

【讨论】:

    【解决方案2】:

    Curator 还附带 curator_cli,您可以在其中运行以下命令以快速进行。

    curator_cli --host https://full-url:port delete_indices --ignore_empty_list --filter_list '[{"filtertype":"pattern","kind":"prefix","value":"logstash-"}]'
    

    【讨论】:

    • 虽然这是真的,但在提出问题时,Curator 版本 4 不存在 curator_cli 功能。
    猜你喜欢
    • 1970-01-01
    • 2012-11-29
    • 2016-11-30
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多