elasticsearch数据迁移
npm install elasticdump -g
# 导出
elasticdump \
--input=http://source-es:9200/my_index \
--output=/path/to/my_index_mapping.json \
--type=mapping
elasticdump \
--input=http://source-es:9200/my_index \
--output=/path/to/my_index_data.json \
--type=data
# 导入
elasticdump \
--input=/path/to/my_index_mapping.json \
--output=http://target-es:9200/my_index \
--type=mapping
elasticdump \
--input=/path/to/my_index_data.json \
--output=http://target-es:9200/my_index \
--type=data
查看索引可以通过浏览器插件es-client
基于Logstash
cat > logstash-es-migration.conf <<EOF
input {
elasticsearch {
hosts => ["http://source-es:9200"]
index => "*" # 迁移所有索引
size => 1000 # 每次读取的文档数
scroll => "5m"
docinfo => true
}
}
output {
elasticsearch {
hosts => ["http://target-es:9200"]
index => "%{[@metadata][_index]}"
document_id => "%{[@metadata][_id]}"
}
}
EOF
bin/logstash -f logstash-es-migration.conf