关于后端:使用-elasticdump-跨版本迁移-ES-数据

3次阅读

共计 1905 个字符,预计需要花费 5 分钟才能阅读完成。

1、elasticdump 用处介绍

elasticdump 是一个在 Github 开源的 Elasticsearch 的数据迁徙工具,我的项目 Github 地址:传送门

elasticdump 反对跨版本导出和导入数据,用法简略,装置不便。

elasti 开发者用了上面一张图来形象的形容了 elasticdump 的作用

elasticdump 具备以下特点

  • 装置不便、应用简略
  • 收费
  • 反对导出为数据文件,亦反对从文件导入到索引
  • 能够间接从 source service 导入到 target service

2、装置 node

应用 node 装置 elasticdump 十分不便。

node 官网:传送门

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.13 8.5
服务地址 http://localhost:9213/ http://localhost:9200/
索引名称 test_index test_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

本文由 mdnice 多平台公布

正文完
 0