es集群遷移,大規模遷移過程中,比如我們以當天時間做索引,在新的es集群會存在和老的es集群一樣的索引文件名,這個時候用snapshot恢復數據會出現沖突問題。這里我們可以用reindex api來解決:
這里有兩種方式使用
1.先在原來的es集群將遷移當天的索引文件名reindex,然后做快照,然后用快照恢復重命名的快照,然后重新reindex恢復
2.先在原來的es集群做快照,然后在新es集群做當日索引文件reindex,然后刪除新生成的索引文件,然后從snapshot恢復當日索引文件,然后將當日新數據做reindex 恢復。
這里舉例第二種方式:
1.查看索引文件
curl 10.0.67.23:9200/_cat/indices/adsense-2017.*
2.做reindex
curl -XPOST '10.0.67.23:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
"source": {
"index": "adsense-2017.11.22-new"
},
"dest": {
"index": "adsense-2017.11.22"
}
}
'
3.刪除當日索引文件
curl -XDELETE '10.0.67.23:9200/adsense-2017.11.22'
4.導入老集群當日索引文件
curl -XPOST "10.0.67.21:9200/_snapshot/es_backup/snapshot-20171123-16/_restore" -d'{ "indices": "adsense-2017.11.22" }'
5.將當日新數據重新合並到老集群索引文件
curl -XPOST '10.0.67.23:9200/_reindex?pretty' -H 'Content-Type: application/json' -d' { "source": { "index": "adsense-2017.11.22-new" }, "dest": { "index": "adsense-2017.11.22" } } '