reindex
官方文檔:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docs-reindex.html
_reindex API支持以某個索引爲數據源構建一個新的索引。
如果elasticsearch的版本小於5.0,_reindex API只支持集羣內部的索引重構遷移。
如果elasticsearch的版本爲5.0及以上,不僅支持集羣內部的索引重構遷移,而且支持從一個集羣遷移數據到另一個集羣,並且可以跨版本遷移,如果需要由低版本elasticsearch升級到高版本就可以採用這種方式。
參考:https://blog.csdn.net/qq_36666651/article/details/83792167
同時elasticsearch提供了ingestNODE,可以用於數據清洗等。
elasticsearch-dump
如果集羣版本較低,要進行數據遷移,就需要使用第三方的elasticsearch-dump工具。
github地址:https://github.com/taskrabbit/elasticsearch-dump
安裝
# elasticsearch-dump採用node.js 所以需要先安裝環境
yum -y install epel-release
yum -y install nodejs
# 檢查
node --version
npm --version
# elasticdump
npm install elasticdump -g
遷移
# 詳細參數參考github的文檔描述
node --max-old-space-size=2048 /usr/bin/elasticdump \
--input=http://172.16.13.14:9200/index_name \
--output=http://192.168.3.41:9200 \
--limit=20000
PS:還一個類似的工具Elasticsearch-Exporter
logstash
參考 https://www.jianshu.com/p/97dbaf78359b
配置文件示例
input {
elasticsearch {
hosts => "172.16.13.14:9200" #配置 elasticsearch的地址及index
index => "test_index"
query => '{ "query": {"match_all" : {} } }' #配置匹配模式
size => 10000 #配置遍歷數據
scroll => "5m" # 配置遍歷時間間隔
docinfo => true
}
}
output {
elasticsearch {
hosts => ["192.168.3.20:9200"]
index => "test_index"
}
}