一、环境准备
1、安装elasticdump
root权限下,终端中输入 ,我的在WSL中安装的docker,所以在wsl中安装
# npm install elasticdump -g
-g表示全局
直接在终端输入 elasticdump --version,出现版本信息即表示安装成功,如下
# elasticdump --version
6.107.0
二、 数据导出至本地、本地数据导入
格式:elasticdump --input {protocol}://{account}:{password}@{host}:{port}/{index} --output ./test_index.json
# 导出当前索引的Mapping结构
elasticdump --input=http://esIP:9200/index_name --output=/host/mnt/d/my_index_mapping.json --type=mapping
# 导出当前索引下的所有真实数据
elasticdump \
--input=http://esIP:9200/index_name \
--output=/host/mnt/d/my_index.json \
--type=data
# 创建索引
$ curl -XPUT http:192.168.56.104:9200/index_name001
# Mapping 数据导入至索引
./bin/elasticdump \
--input=/home/indexdata/roll_vote_mapping.json \ # 导入数据目录
--output=http://es实例IP:9200/index_name001 \
--type=mapping
# ES文档数据(真实数据)导入至索引
./bin/elasticdump \
--input=/home/indexdata/roll_vote.json \
--output=http://es实例IP:9200/index_name001 \
--type=data
也可以将查询的结果导出到本地文件
# Backup the results of a query to a file
elasticdump \
--input=http://production.es.com:9200/my_index \
--output=query.json \
--searchBody="{\"query\":{\"term\":{\"username\": \"admin\"}}}"
三 、ES直接之间的数据迁移
前提:需在同一网络下,可以相互访问
# ES到ES的导入
elasticdump \
--input=http://192.166.1.101:9200/test \
--output=http://192.166.1.110/test
elasticdump 适合小批量的数据进行迁移,如果数据量比较大,请使用es的快照 snapshot.