項目中需要對Elasticsearch 中的數據進行定時清理,經過網上資料搜索和部分實踐,對於ES的生命週期發展歷程,進行了大致整理,僅供參考。
1、ES5.0以前的版本可以通過設置ttl處理:
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-ttl-field.html
移除ttl原因:https://discuss.elastic.co/t/ttl-gone-in-5-0-omg/93028/2
2、網上目前提供常用解決辦法(手動在ES6.2.3上實踐了下是可行的):
1)基於delete-by-query方法刪除特定時間範圍的數據
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_mapping_changes.html#_literal__timestamp_literal_and_literal__ttl_literal https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_mapping_changes.html#_literal__ttl_literal_and_literal__timestamp_literal_cannot_be_created
2)使用基於時間的索引,如logstash-2019-01-02,可以使用官方的Curator工具,注意Curator是無法實現刪除索中的某一段數據的。
https://blog.csdn.net/laoyang360/article/details/85882832
3、Index LifeCycle Management(有說在ES6.3就有,但是官網正式發佈是在ES6.6版本,暫未實踐)
https://www.elastic.co/guide/en/elasticsearch/reference/master/index-lifecycle-management-api.html
https://elasticsearch.cn/article/6358
4、執行刪除操作,但磁盤空間不減少問題,確認是刪除文檔還是刪除索引