0、引言

将ES中的索引拷贝到其他ES中,或者将ES整体迁移,研究发现有两个开源的工具:elaticserch-dump和 Elasticsearch-Exporter。
除此之外,logstash在索引同步、迁移方面的作用也很大。
两工具及logstash实现迁移的介绍、安装、使用、验证效果等展示如下:

1、elasticsearch-dump迁移

1.1 elasticsearch-dump简介

Tools for moving and saving indicies. 从来移动和保存索引的工具。
https://github.com/taskrabbit/elasticsearch-dump

1.2 elasticsearch-dump安装

1) yum install epel-release
2) yum install nodejs
3) yum install npm
4) npm install elasticdump
5) cd node_modules/elasticdump/bin  后便可以执行操作。
  • 1
  • 2
  • 3
  • 4
  • 5

安装后如下所示:

[root@N3 elasticdump]# pwd
/home/tp/node_modules/elasticdump
[root@N3 elasticdump]# ls -al
total 388
drwxr-xr-x 2 root root 4096 Mar 21 15:46 bin
-rw-r--r-- 1 root root 174 Mar 18 2016 Dockerfile
-rw-r--r-- 1 root root 299251 Mar 15 2014 elasticdump.jpg
-rw-r--r-- 1 root root 6172 Feb 2 23:47 elasticdump.js
drwxr-xr-x 2 root root 4096 Jul 13 2016 .github
drwxr-xr-x 3 root root 4096 Mar 21 15:46 lib
-rw-r--r-- 1 root root 11356 May 22 2014 LICENSE.txt
drwxr-xr-x 10 root root 4096 Mar 21 15:46 node_modules
-rw-r--r-- 1 root root 44 May 22 2014 .npmignore
-rw-r--r-- 1 root root 15135 Mar 21 15:46 package.json
-rw-r--r-- 1 root root 13335 Dec 14 06:20 README.md
drwxr-xr-x 3 root root 4096 Mar 21 15:46 test
-rw-r--r-- 1 root root 1150 Dec 2 07:54 .travis.yml
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

1.3 elasticsearch-dump 使用

'#拷贝analyzer如分词
elasticdump \--input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=analyzer
'#拷贝映射
elasticdump \--input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping
'#拷贝数据
elasticdump \--input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=data
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

1.4 elasticsearch-dump实战小结

源ES版本1.6.0,目标ES版本:2.3.4,验证发现:analyzer和mapping可以拷贝成功。
但是,data拷贝不成功。目标机器ES中不能显示出数据。根本原因没有排查到。

2、 Elasticsearch-Exporter迁移

2.1 Elasticsearch-Exporter简介

https://github.com/mallocator/Elasticsearch-Exporter
A small script to export data from one Elasticsearch cluster into another. 将ES中的数据向其他导出的简单脚本实现。

2.2、Elasticsearch-Exporter安装

http://www.dahouduan.com/2014/12/25/centos-yum-install-nodejs-npm/
centos用 yum 方式安装 nodejs 和 npm

npm install nomnom
npm install colors
npm install elasticsearch-exporter --production
  • 1
  • 2
  • 3

安装后:

[root@N3 elasticsearch-exporter]# ll -ls
total 804 drwxr-xr-x 2 root root 4096 Mar 21 22:01 drivers
12 -rw-r--r-- 1 root root 11523 Sep 19 2014 exporter.js
12 -rw-r--r-- 1 root root 11324 Mar 16 2014 LICENSE4 drwxr-xr-x 4 root root 4096 Mar 21 22:01 node_modules
12 -rw-r--r-- 1 root root 11259 Sep 19 2014 options.js
16 -rw-r--r-- 1 root root 14500 Mar 21 22:01 package.json
16 -rw-r--r-- 1 root root 12645 Sep 19 2014 README.md4 drwxr-xr-x 2 root root 4096 Apr 25 2014 tools
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2.3、 Elasticsearch-Exporter使用

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

即可实现跨机器索引的迁移。

更多的参数可以查看node exporter.js –help

[root@N3 elasticsearch-exporter]# node exporter.js --help
Elasticsearch Exporter - Version 1.4.0
Usage: exporter [options]
Options:-a <hostname>, --sourceHost <hostname>  迁移源机器地址-b <hostname>, --targetHost <hostname>  迁移目的机器地址(如果没有设置索引,目的地址需要有别于源地址)-p <port>, --sourcePort <port>   源机器的ES的端口,9200(一般)-q <port>, --targetPort <port>    目标机器的ES的端口,9200(一般)-i <index>, --sourceIndex <index> 源ES待导出的索引,如果该值不设定,整个的数据库都会导出。-j <index>, --targetIndex <index>目标机器ES的索引,如果源索引设定,该值必须填写。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2.4、 Elasticsearch-Exporter 索引迁移实战(验证ok)

[root@No3 elasticsearch-exporter]# node exporter.js -a 10.221.110.31-b 100.0.1.130 -p 9200 -q 9200 -i awppx -j awppx
同步最后会显示:
Number of calls: 169
Fetched Entries: 8064 documents
Processed Entries: 8064 documents
Source DB Size: 8064 documents
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

代表同步成功。
源ES版本1.6.0,目标ES版本:2.3.4,
验证发现:可以使用 Elasticsearch-Exporter跨机器、跨ES版本同步索引成功。

3、logstash定向索引迁移

[root@N3 bin]# cat ./logstash_output_mongo/logstash_es22es.conf
input {elasticsearch {hosts => [ "100.200.10.54:9200" ]index => "doc"size => 1000scroll => "5m"docinfo => truescan => true}
}filter {
json {source => "message"remove_field => ["message"]}mutate {# rename field from 'name' to 'browser_name'rename => { "_id" => "wid" }
}
}output {elasticsearch {hosts => [ "100.20.32.45:9200" ]document_type => "docxinfo"index => "docx"}stdout {codec => "dots"}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

4、小结
对比发现, Elasticsearch-Exporter在索引迁移方面相对更好用。(待深入研究补充)
而logstash定向索引用于辅助解决 Elasticsearch-Exporter不同版本迁移有Bug的情形。

来源:http://blog.csdn.net/laoyang360/article/details/65449407

Elasticsearch索引迁移的三种方式相关推荐

  1. 【创建索引的三种方式】

    创建索引的三种方式 第一种方式:在执行 CREATE 第二种方式:使用 ALTER TABLE 命令去增加索 ALTER TABLE table_name ADD INDEX index_name ( ...

  2. 创建索引的三种方式以及删除索引

    1.第一种方式:在执行CREATE TABLE时创建索引 CREATE TABLE user_index( #建立主键索引并设置自增 id INT auto_increment PRIMARY KEY ...

  3. win下配置的ES中的数据在哪里可以看到?三种方式你看那种更加高大上!!!(win_Elasticsearch)

    在上一篇博客<使用logstash将Mysql中的数据导入到ElasticSearch中(详细步骤,win_Elasticsearch)>中我们提到将数据插入到es中,那我怎么知道数据是否 ...

  4. 数据导入HBase最常用的三种方式及实践分析

    要使用Hadoop,数据合并至关重要,HBase应用甚广.一般而言,需要针对不同情景模式将现有的各种类型的数据库或数据文件中的数据转入至HBase中. 常见方式为:1.使用HBase的API中的Put ...

  5. Docker的常用管理命令Docker将数据挂载到容器的三种方式

    文章目录 镜像管理命令 容器管理常用命令 docker run常用参数 Docker run的其他参数 docker 创建容器命令 容器资源限制 docker管理容器常用命令 docker将数据挂载到 ...

  6. Python必学内容:格式化输出的三种方式

    1. 格式化输出的三种方式 在程序中,需要将输出信息打印成固定的格式,这时候就需要格式化输出. 1.1 占位符 这种格式化输出方式与C语言中的类似,使用 %s 占位,再将后面%号后括号内的变量依次传给 ...

  7. android xml解析的三种方式

    2019独角兽企业重金招聘Python工程师标准>>> 在android开发中,经常用到去解析xml文件,常见的解析xml的方式有一下三种:SAX.Pull.Dom解析方式.最近做了 ...

  8. 图神经网络(一)图信号处理与图卷积神经网络(1)矩阵乘法的三种方式

    图神经网络(一)图信号处理与图卷积神经网络(1)矩阵乘法的三种方式 1.1 矩阵乘法的三种方式 参考文献   图信号处理(Graph Signal Processing,GSP) 1是离散信号处理(D ...

  9. Android之解析XML总结(SAX、Pull、Dom三种方式)

    常见的解析xml的方式有一下三种:SAX.Pull.Dom解析方式.最近做了一个android版的CSDN阅读器,用到了其中的两种(sax,pull),今天对android解析xml的这三种方式进行一 ...

最新文章

  1. UIScrollView
  2. AIの幕后人:探秘“硬核英雄”的超级武器
  3. POJ-2531 Network Saboteur 枚举||随机化
  4. 直播实录 | 哈工大博士生周青宇:从编码器与解码器端改进生成式句子摘要
  5. Linux下screen的应用
  6. 【疑难杂症】vmware虚拟机提示“该虚拟机似乎正在使用中”,并且无法获取所有权解决办法(三步解决虚拟机vmware提示正在使用中的问题)
  7. win10下markdownpad2显示问题
  8. 1过程流程图 3 apqp_为什么过程开发的平面布置图要遵循精益原则?
  9. android+水滴粘性动画,Android控件实现水滴效果
  10. windows nginx 停止和启动_大数据离线项目实践之nginx服务器搭建
  11. postgresql 索引状态_PostgreSQL中的锁:3.其他锁
  12. 面向对象——类设计(七)
  13. C#4.0的十种语法糖
  14. 小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
  15. windows 2003 server IIS权限设置
  16. 常见设计稿字体对应字重font-weight大小
  17. 从零开始pytorch手写字母识别
  18. 性能测试流程、优化、指标
  19. 买到Windows新电脑必做的6个优化设置(强烈建议)
  20. 阿里云服务器华东 1、华东 2、华北 1、华北 2、华南 1 是哪个城市

热门文章

  1. 04_机器学习概述,什么是机器学习,应用场景,数据来源与类型,网上可用的数据集、常用数据集数据的结构组成、特征工程是什么、意义、特征抽取、sklearn特征抽取API、文本特征抽取(学习笔记)
  2. 最全的IO操作知识总结
  3. 配置虚拟目录的方式(Linux下/windows下)
  4. \r与\n的区别,以及\r\n的用法
  5. Window系统下C/C++程序毫秒和微秒级程序运行时间的获取方法
  6. Faster R-CNN论文及源码解读
  7. 浅谈linux字符设备注册
  8. 区间贪心算法-——活动安排问题
  9. Netty ByteBuf(图解之 2)| 秒懂
  10. CSS鼠标响应事件经过、移动、点击示例介绍