Elasticsearch迁移

本文深入探讨了Elasticsearch数据迁移的各种方法,包括elasticsearch-dump、snapshot、reindex及logstash,详细介绍了每种方法的适用场景和具体操作步骤,为ES数据迁移提供了全面的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

迁移办法的几个办法:elasticsearch-dump  snapshot reindex logstash

公司迁移es,因数据量不是很大,采用的方法elasticsearch-dump的方式进行数据迁移

elasticsearch-dump:主要针对数据量小的情况,而且迁出迁入服务器网络通

elasticsearch-dump 是一款开源的es迁移工具,github地址:https://github.com/taskrabbit/elasticsearch-dump

它基于node.js开发,可以直接nmp安装:

npm install elasticdump -g

迁移命令:

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

input 输入源es地址的index索引,output 目标源es地址以及index索引,type迁移的类型,可选settings, analyzer, data, mapping, alias

同一个index的type迁移顺序为:settings(配置,首位)->analyzer(分词,需要在mapping前)->mapping(映射)->alias->data

如果网络不通的情况下,也可以output输出到file中,详细可以看官方github中remark中使用介绍.

需要auth用户密码的可以参考下面的办法

# 注意 elasticdump 提供给了--httpAuthFile 参数来做认证
--httpAuthFile      When using http auth provide credentials in ini file in form
                    `user=<username>
                    password=<password>`

# 只需要写一个ini文件 ,文件中写入用户名和密码就可以了
# 这里其实还有另外一个好的方法
# 在--input参数和--output参数的的url中添加账号密码
# 例如
elasticdump \
  --input=http://prod-username:prod-passowrd@production.es.com:9200/my_index \
  --output=http://stage-username:stage-password@staging.es.com:9200/my_index \
  --type=data

 

snapshot

适用场景

适用数据量大的场景

使用方式

snapshot api是Elasticsearch用于对数据进行备份和恢复的一组api接口,可以通过snapshot api进行跨集群的数据迁移,原理就是从源ES集群创建数据快照,然后在目标ES集群中进行恢复。需要注意ES的版本问题:

reindex

reindex是Elasticsearch提供的一个api接口,可以把数据从源ES集群导入到当前的ES集群,同样实现了数据的迁移,限于腾讯云ES的实现方式,当前版本不支持reindex操作。简单介绍一下reindex接口的使用方式。

logstash

logstash支持从一个ES集群中读取数据然后写入到另一个ES集群,因此可以使用logstash进行数据迁移,具体的配置文件如下:

snapshot、reindex、logstash更详细介绍参看:https://cloud.tencent.com/developer/article/1145944

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值