暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用 elasticdump 跨版本迁移 ES 集群

Elasticsearch之家 2022-11-25
651

长按加关注,更多干货内容不错过

1、elasticdump 用途介绍

elasticdump 是一个在 Github 开源的 Elasticsearch 的数据迁移工具,项目 Github 地址:[传送门](Github 地址:https://github.com/elasticsearch-dump/elasticsearch-dump)

elasticdump 支持跨版本导出和导入数据,用法简单,安装方便。

elasti开发者用了下面一张图来形象的描述了 elasticdump 的作用

elasticdump 具有以下特点

  • 安装方便、使用简单
  • 免费
  • 支持导出为数据文件,亦支持从文件导入到索引
  • 可以直接从 source service 导入到 target service

2、安装 node

使用 node 安装 elasticdump 非常方便。

node 官网:https://nodejs.org/en/

3、安装 elasticdump

3.1 基于本地安装

本地安装:使用时较为麻烦,不推荐

npm install elasticdump

复制

Mac 系统下默认安装位置为:/Users/<user_name>/node_modules/elasticdump

启动

./bin/elasticdump

复制

3.2 基于全局安装(推荐)

sudo npm install elasticdump -g

复制

4、准备数据源服务和目标服务

博主准备了以下两个服务,将在本文第 6 小节演示数据的迁移

具体信息如下:


源数据服务:source目标数据服务:data
版本号7.138.5
服务地址http://localhost:9213/http://localhost:9200/
索引名称test_indextest_index

5、使用方法

5.1 一行代码看懂用法

elasticdump --input <源数据> --output <目标数据> --type=<数据类型>

复制

5.2 数据源或者目标数据可以是文件或者 URL

源数据服务或者目标数据服务配置方法如下

Elasticsearch:

  • format: {protocol}://{host}:{port}/{index}
  • example: http://127.0.0.1:9200/my_index

File:

  • format: {FilePath}
  • example: Users/evantahler/Desktop/dump.json

5.3 重要选项

  • input:源数据的位置,此项为必须项
  • output:目标数据的保存位置:此项为必须项
  • type:默认为 data
    ,

    支持以下可选项:

    • settings
    • analyzer
    • data
    • mapping
    • policy
    • alias
    • template
    • component_template,
    • index_template

6、案例

6.1 以数据文件形式迁移

以文件方式导入导出,如果数据量很大,会占用很大的磁盘空间

6.1.1 导出源数据的 mapping 和 data

1:导出源数据索引的 mapping

在导出数据的时候,需要指定导出的数据类型

elasticdump --input http://localhost:9213/test_index --output /Users/wu/Desktop/test_index_mapping.json --type=mapping

复制

2:导出指定索引的 data 为文件

elasticdump --input http://localhost:9213/test_index --output /Users/wu/Desktop/test_index.json --type=data

复制

6.1.2 将导出的数据文件导入至目标索引

1:创建目标索引的空索引

// curl -XPUT http:localhost:9200/test_index
PUT test_index

复制

2:导入 mapping 至目标索引

elasticdump --input /Users/wu/Desktop/test_index_mapping.json --output http://localhost:9200/ --type=mapping

复制

3:导入 data 至目标索引

$ elasticdump --input /Users/wu/Desktop/test_index.json --output http://localhost:9200/ --type=data

复制

6.2 从数据源直接导入到目标集群

6.2.1 迁移 mapping

elasticdump --input http://localhost:9213/test_index --output http://localhost:9200/ --type=mapping

复制

6.2.2 迁移 data

elasticdump --input http://localhost:9213/test_index --output http://localhost:9200/ --type=data
复制

长按加关注,更多干货内容不错过


无论您漂泊到何处

这里都是您的灵魂树洞

长按识别二维码关注我们





文章转载自Elasticsearch之家,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论