有个人长的像洋葱,走着走着就哭了…….

elasticsearch定时删除旧的index内容

Elasticsearch | 作者 chengxiaomeng | 发布于2017年05月17日 | 阅读数:8740

我们有些数据量小业务的日志是按照年保存的(index:logstash-chat-2017),但是有些数据量大的业务是按照天来保存的(index:logstash-bigchat-2017-03-02)。如果按照官方文档设置_delete_by_query,我们可不可以对以年为index:logstash-chat-2017的数据进行删除30天以前的数据?但是不影响30天以内的数据?求大神???


下面的命令可以删除7天以前的数据吗?
curl -u 用户名:密码 -H'Content-Type:application/json' -d'{
"query": {
"range": {
"@timestamp": {
"lt": "now-7d",
"format": "epoch_millis"
}
}
}
}
' -XPOST "http://127.0.0.1:9200/logstash ... ot%3B

已邀请:

wyntergreg

赞同来自:

@timestamp字段是可以自己填写的,自己构造点数据试试喽

wuyinggui - elastic

赞同来自:

官网有推荐工具,名字叫curator,需要python支持
elasticsearch curator自动删除索引

pip install elasticsearch-curator

curator_cli --host 127.0.0.1 --port 9200 delete_indices --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"seconds","unit_count":13},{"filtertype":"pattern","kind":"prefix","value":"abc"}]'

要回复问题请先登录注册