How to delete elastic search indices periodically?

别等时光非礼了梦想. 提交于 2019-12-04 21:42:51

The only thing I can think of is using data math: https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html

In sense you can do this:

DELETE <logs-{now%2Fd-10d}>

This does not work nice in curl though due to url encoding. You can do something like this in curl:

curl -XDELETE 'localhost:9200/<logs-%7Bnow%2Fd-10d%7D>'

Both examples remove the index that is 10 days old. It does not help you in deleting indices older than 10 days, don't think that is possible. And their is no trigger or something in elasticsearch.

So I would stick to a cron job in combination with curator, but you do have this option to go with as well.

alpert

I don't know if elasticsearch has a built-in feature like that but you can achieve what you want with curator and a cron job.

An example curator command is:

Curator 3.x syntax [deprecated]:

curator --host <IP> delete indices --older-than 10 --prefix "index-prefix-" --time-unit days  --timestring '%Y-%m-%d'

Curator 5.1.1 syntax:

curator_cli --host <IP> --port <PORT> delete_indices --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":10},{"filtertype":"pattern","kind":"prefix","value":"index-prefix-"}]'

Run this command daily with a cron job to delete indices older than 10 days whose names start with index-prefix- and that live on the Elasticsearch instance at <IP>:<PORT>.

For more curator command-line options, see: https://www.elastic.co/guide/en/elasticsearch/client/curator/current/singleton-cli.html

For more on cron usage, see: http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!