【elasticsearch】使用工具迁移索引数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014587343/article/details/50541494

大家都知道,Elasticsearch手动迁移索引到其他机器上是一件非常麻烦的事情。

1. Elasticsearch-dump

这个是我比较常用的一个工具
1) yum install epel-release

2) yum install nodejs

3) yum install nodejs npm

4) npm install elasticdump

5) cd node_modules/elasticdump/bin

6)./elasticdump  --input=http://192.168.1.1:9200/original --output=http://192.168.1.2:9200/newCopy --type=data
第6步是迁移到新索引的命令。需要注意的是如果只使用这个命令的话,目的索引必须先手动创建一下mapping,不然迁移过去类型会自动判断,date类型判断成string等等

如果你很懒你不想自己创建索引,那么你可以在执行6)之前做一下:

./elasticdump  --input=http://192.168.1.1:9200/original --output=http://192.168.1.2:9200/newCopy --type=mapping
 
 
 
 

不一样的地方就是--type=mapping ,意思是把原始索引的mapping结构迁移给目标索引。然后在执行--type=data的6)就可以把数据迁移过去啦

如果索引很多,你还是懒得一个个去迁移,那么你可以改用这个命令:

./elasticdump  --input=http://192.168.1.1:9200/ --output=http://192.168.1.2:9200/ --all=true
加个--all=true,input与output里不需要把索引名加上,这样就可以自动把原机器上的所有索引迁移到目标机器


2. Elasticsearch-exporter

npm install nomnom
npm install colors
npm install elasticsearch-exporter --production

node exporter.js -a <source hostname> -b <target hostname> -p <s port> -q <t port> -i <s index> -j <t index>

即可实现索引的迁移。更多的参数可以查看node exporter.js --help


3.

另外有一种方法是通过分片规则来手动控制的。大致原理是控制索引的分片只分布在配置里a标签的值为b的节点上。然后把目标机器加入集群,撤去原机器的标签。索引便会转移到目标机器上面。

这个方法是在别的地方看到的,具体我也没试验过。有兴趣的可以试一下



猜你喜欢

转载自blog.csdn.net/u014587343/article/details/50541494