利用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
posted @ 2019-09-30 11:25  agang_19  阅读(1058)  评论(0编辑  收藏  举报