我每天创建索引来存储搜索历史,我正在使用这些索引在我的应用程序中提出建议,这也有助于我基于历史提出建议。
现在我只需要维护最近10天的历史记录。那么Elastic search中有没有什么功能可以让我定期创建和删除索引呢?
发布于 2016-07-27 13:55:06
我唯一能想到的就是使用数据数学:https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html
从某种意义上说,你可以这样做:
DELETE <logs-{now%2Fd-10d}>然而,由于url编码,这在curl中不能很好地工作。你可以在curl中这样做:
curl -XDELETE 'localhost:9200/<logs-%7Bnow%2Fd-10d%7D>'这两个示例都删除了10天前的索引。它不能帮助你删除超过10天的索引,不要认为这是可能的。他们在elasticsearch中没有触发器或其他东西。
因此,我会坚持一个cron的工作,并结合馆长,但你也有这个选择。
发布于 2016-07-27 03:35:41
我不知道elasticsearch是否有这样的内置功能,但你可以使用curator和cron作业来实现你想要的功能。
curator命令示例如下:
Curator 3.x语法已弃用
curator --host <IP> delete indices --older-than 10 --prefix "index-prefix-" --time-unit days --timestring '%Y-%m-%d'Curator 5.1.1语法:
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-"}]'每天对cron作业运行此命令,以删除名称以index-prefix-开头且位于<IP><PORT>的Elasticsearch实例上的超过10天的索引。
有关管理员命令行选项的更多信息,请参阅:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/singleton-cli.html
有关cron用法的更多信息,请参阅:http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/
https://stackoverflow.com/questions/38597842
复制相似问题