利用elasticsearch-dump实现es索引数据迁移附脚本

1、安装环境

CentOS Linux release 7.5.1804 (Core)
  • 1

2、安装nodejs

yum install -y nodejs
  • 1

3、验证nodejs

[root@localhost yum.repos.d]# node -v
v8.12.0
[root@localhost yum.repos.d]# npm -v 6.4.1 
  • 1
  • 2
  • 3
  • 4

4、安装elasticsearch-dump

npm install elasticdump
  • 1

5、验证安装

进入elasticdump/bin目录下

cd node_modules/elasticdump/bin/
  • 1

执行

 ./elasticdump
  • 1

出现

Fri, 19 Oct 2018 07:03:15 GMT | Error Emitted => {"errors":["`input` is a required input","`output` is a required input"]} 
  • 1

报错是因为没有输入参数

6、使用dump迁移索引

#拷贝索引

elasticdump 
	--input=http://production.es.com:9200/my_index 
	--output=http://staging.es.com:9200/my_index 
	--type=mapping
  • 1
  • 2
  • 3
  • 4

#拷贝数据

elasticdump 
	--input=http://production.es.com:9200/my_index 
	--output=http://staging.es.com:9200/my_index 
	--type=data
  • 1
  • 2
  • 3
  • 4

#拷贝所有索引

elasticdump  
	--input=http://production.es.com:9200/ 
	--output=http://staging.es.com:9200/ 
	--all=true  
  • 1
  • 2
  • 3
  • 4

7、迁移实战

为了方便操作写了一个脚本,仅供参考。

#!/bin/bash
echo -n "源ES地址: "
read old
echo -n "目标ES地址: " read new echo -n "源索引名: " read old_index echo -n "目标索引名: " read new_index cd /root/node_modules/elasticdump/bin/ ./elasticdump --input=$old/$old_index --output=$new/$new_index --type=mapping &>> /root/dump.log ./elasticdump --input=$old/$old_index --output=$new/$new_index --type=data &>> /root/dump.log

转载于:https://www.cnblogs.com/agang-php/p/11611769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值