【ElasticSearch】elasticdump 导入/导出数据

一、环境准备

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.

参考:【精选】【ElasticSearch】elasticdump 导入/导出数据及常见报错_dump ended with error (get phase) => [object objec-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值