有两种方式实现:
1、快照和还原
2、导出和导入
一、快照和还原
1、在源Elasticsearch集群上创建快照存储库
PUT _snapshot/my_backup
{"type": "fs","settings": {"location": "/path/to/backup/directory"}
}
2、创建快照
PUT _snapshot/my_backup/snapshot_1
{"indices": "index1,index2","ignore_unavailable": true,"include_global_state": false
}
3、在还原库上创建同样的快照存储库
PUT _snapshot/my_backup
{"type": "fs","settings": {"location": "/path/to/backup/directory"}
}
4、从快照还原
POST _snapshot/my_backup/snapshot_1/_restore
{"indices": "index1,index2","ignore_unavailable": true,"include_global_state": false
}
二、使用导出和导入进行备份和恢复
1、导出索引数据
POST _export
{"indices": "index1,index2","query": {"match_all": {}},"size": 1000,"sort": ["_doc"]
}
2、导入数据
POST _import
{"index": "index1","data": [{"index": {"_id": "1"}},{"field1": "value1", "field2": "value2"},{"index": {"_id": "2"}},{"field1": "value3", "field2": "value4"}]
}