Elasticsearch清理生产无用数据参考

示例

索引: test_index
备份索引:test_index_bak190810
清理条件:creationDate 时间范围限制
字段限制:userId

操作步骤

1. 先备份清理数据

  curl -XPOST "http://127.0.0.1:9200/_reindex?pretty" -H "Content-Type: application/json" -d'{"source": {"index": "test_index","query": {"bool": {"must": [{"range": {"creationDate": {"gt": "2019-07-20","lt": "2019-08-10"}}}],"must_not": [{"exists": {"field": "userId"}}],"should": []}}},"dest": {"index": "test_index_bak190810","version_type": "internal"}}'

2. 清理数据

  curl -X POST "http://127.0.0.1:9200/test_index/_delete_by_query?pretty" -H 'Content-Type: application/json' -d'{ "query": {"bool": {"must": [{"range": {"creationDate": {"gt": "2019-07-20","lt": "2019-08-10"}}}],"must_not": [{"exists": {"field": "userId"}}],"should": []}}}'

3. 如有问题,还原清理的数据

  curl -X POST "http://127.0.0.1:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'{"source": {"index": "test_index_bak190810"},"dest": {"index": "test_index"}}'

4. 没问题后,清理备份数据

  curl -XDELETE http://127.0.0.1:9200/test_index_bak190810

知识点

_reindex?pretty

  https://www.elastic.co/guide/en/elasticsearch/reference/7.6/docs-reindex.html

_delete_by_query

  https://www.elastic.co/guide/en/elasticsearch/reference/7.6/docs-delete-by-query.html

猜你喜欢

转载自www.cnblogs.com/bensonwei/p/12757999.html