elasticdump和ESM

逐个执行如下命令;

1.拷贝analyzer如分词(需要分词器,可能不成功,不影响复制)
./elasticdump --input=http://[来源IP地址]:9200/[来源索引]  --output=http://[目标IP地址]:9200/[目标索引] --type=analyzer
2.拷贝映射
./elasticdump --input=http://[来源IP地址]:9200/[来源索引]  --output=http://[目标IP地址]:9200/[目标索引] --type=mapping
3.拷贝数据
./elasticdump --input=http://[来源IP地址]:9200/[来源索引]  --output=http://[目标IP地址]:9200/[目标索引] --type=data

恢复顺序是:1、先分词;2、索引、3、数据

注:如查不迁移分词,替换为空值
例:  替换分词
  sed -i 's/,"analyzer":"ik_analyzer"//g'  geometry_955_mapping.json

elasticdump \
  --input=http://192.168.1.140:9200/source_index \
  --output=http://192.168.1.141:9200/target_index \
  --type=data \
  --limit=2000  # 每次操作的objects数量,默认100,数据量大的话,可以调大加快迁移速度
 --input=http://172.30.40.125:9200/geometry_833 \
--output=http://47.105.38.107:9200/geometry_833

 导出索引结构
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index_mapping.json \
  --type=mapping

  导出索引数据
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index.json \
  --type=data 
 

elasticdump  --input=http://172.30.40.125:9200/geometry_833   --output=/mysqldata/es20240516/geometry_833_mapping.json  --type=mapping
elasticdump  --input=http://172.30.40.125:9200/geometry_833   --output=/mysqldata/es20240516/geometry_833.json  --type=data 
 
 
 导入索引和数据

elasticdump \
  --input=/data/source_index_mapping.json \
  --output=http://192.168.1.141:9200/source_index \
  --type=mapping
elasticdump \
  --input=/data/source_index.json \
  --output=http://192.168.1.141:9200/source_index \
  --type=data \
  --limit=2000
 
 elasticdump 所有索引
elasticdump --input=./indices.json --output=http://localhost:9201 --all=true 


elasticdump 所有数据

elasticdump --input=http://localhost:9200/ --output=all_data.json --all=true
这里的参数解释如下:
--input:指定 Elasticsearch 实例的地址。
--output:指定导出的文件名。
--all=true:指示 elasticdump 导出所有的数据。

 
elasticdump --input=/data/source_index_mapping.json --output=http://192.168.1.141:9200/source_index  --type=mapping
elasticdump  --input=/data/source_index.json --output=http://192.168.1.141:9200/source_index --type=data 
 
elasticdump --input==/mysqldata/es20240516/geometry_833_mapping.json --output=http://47.105.38.107:9200/geometry_833  --type=mapping
elasticdump --input==/mysqldata/es20240516/geometry_833.json --output=http://47.105.38.107:9200/geometry_833  --type=data
 
 #es如果有密码,执行以下语句
elasticdump \
  --input=http://username:passowrd@production.es.com:9200/my_index \
  --output=http://username:password@staging.es.com:9200/my_index \
  --type=data
  
  替换分词
  sed -i 's/,"analyzer":"ik_analyzer"//g'  geometry_955_mapping.json
 sed -i 's/,"analyzer":"ik_analyzer"//g' 1.json   
 
 大量数据迁移
 
 #ESM迁移工具【适合大数据量】

解析:esm迁移过程原理与elasticsearch-dump类似,区别在于esm使用go语言开发,号称每分钟可以迁移一千万条数据

下载地址:wget https://github.com/medcl/esm/releases/download/v0.7.0/esm-linux-amd64

1、数据迁移

授权:chmod +x esm-linux-amd64

./esm-linux-amd64 -s http://192.168.1.x.:9200 -m 账户:密码 -x "索引名称" -d http://192.168.2.x:9200 -n "账户:密码" -c 10000 -w10 -b=20 -f --refresh

解析:

-s表示读取数据源SOURCE
-d表示将数据源传输到目的地DESTINATION。
-x表示需要复制的索引名称
-q表示指定条件的查询语句
-n表示base认证的用户名和密码
-w表示并发数,默认为1
-b表示buck大小,默认5MB
-f表示复制前删除已有重名索引
–refresh表示完成后再刷新索引


4、下载安装elasticsearch-migration
源码:https://github.com/medcl/esm-abandoned
编译好的工具:https://github.com/medcl/esm-abandoned/releases

下载编译好的工具放到/usr/local/hadoop目录下,解压后可以直接运行,elasticsearch-migration支持linux,windows等不同系统。使用示例

./bin/linux64/esm -s http://10.62.124.x:9200 -d http://10.67.151.y:9200 -x index_name -w=5 -b=10 -c 10000
1
-w 表示线程数
-b 表示一次bulk请求数据大小,单位MB默认 5M
-c 一次scroll请求数量

5、数据迁移
因为需要迁移的索引比较多,大概有几百个,为了提高效率,所以写了一个批量索引迁移脚本:

#!/bin/sh

dir="/usr/local/hadoop"
cd $dir

esIndex=`curl -s 'http://10.62.124.x:9200/_cat/indices' | grep -e mobile_lte_* | awk '{print $3}'`

for indexName in $esIndex

do

    echo "Start migration $indexName"
    ./bin/linux64/esm -s http://10.62.124.x:9200 -d http://10.67.151.y:9200 -x $indexName -y $indexName -w=5 -b=10 -c 10000 --copy_settings --copy_mappings --force  --refresh

done

将该脚本放到/usr/local/hadoop目录下,运行即可。

授权:chmod +x esm-linux-amd64

./esm-linux-amd64 -s http://192.168.1.x.:9200 -m 账户:密码 -x "索引名称" -d http://192.168.2.x:9200 -n "账户:密码" -c 10000 -w10 -b=20 -f --refresh

解析:
-s表示读取数据源SOURCE
-d表示将数据源传输到目的地DESTINATION。
-x表示需要复制的索引名称
-q表示指定条件的查询语句
-n表示base认证的用户名和密码
-w表示并发数,默认为1
-b表示buck大小,默认5MB
-f表示复制前删除已有重名索引
–refresh表示完成后再刷新索引
 

2、使用示例

copy index index_name from 192.168.1.x to 192.168.1.y:9200

./bin/esm  -s http://192.168.1.x:9200   -d http://192.168.1.y:9200 -x index_name  -w=5 -b=10 -c 10000

copy index src_index from 192.168.1.x to 192.168.1.y:9200 and save with dest_index

./bin/esm -s http://localhost:9200 -d http://localhost:9200 -x src_index -y dest_index -w=5 -b=100

support Basic-Auth

./bin/esm -s http://localhost:9200 -x "src_index" -y "dest_index"  -d http://localhost:9201 -n admin:111111

copy settings and override shard size

./bin/esm -s http://localhost:9200 -x "src_index" -y "dest_index" -d http://localhost:9201 -m admin:111111 -c 10000 --shards=50 --copy_settings

copy settings and mapping, recreate target index, add query to source fetch, refresh after migration

./bin/esm -s http://localhost:9200 -x "src_index" -q=query:phone -y "dest_index" -d http://localhost:9201 -c 10000 --shards=5 --copy_settings --copy_mappings --force --refresh

dump elasticsearch documents into local file

./bin/esm -s http://localhost:9200 -x "src_index"  -m admin:111111 -c 5000 -q=query:mixer  --refresh -o=dump.bin 

loading data from dump files, bulk insert to another es instance

./bin/esm -d http://localhost:9200 -y "dest_index"   -n admin:111111 -c 5000 -b 5 --refresh -i=dump.bin

support proxy

 ./bin/esm -d http://123345.ap-northeast-1.aws.found.io:9200 -y "dest_index"   -n admin:111111  -c 5000 -b 1 --refresh  -i dump.bin  --dest_proxy=http://127.0.0.1:9743

use sliced scroll(only available in elasticsearch v5) to speed scroll, and update shard number

 ./bin/esm -s=http://192.168.3.206:9200 -d=http://localhost:9200 -n=elastic:changeme -f --copy_settings --copy_mappings -x=bestbuykaggle  --sliced_scroll_size=5 --shards=50 --refresh

migrate 5.x to 6.x and unify all the types to doc

./esm -s http://source_es:9200 -x "source_index*" -u "doc" -w 10 -b 10 - -t "10m" -d https://target_es:9200 -m elastic:passwd -n elastic:passwd -c 5000

to migrate version 7.x and you may need to rename _type to _doc

./esm -s http://localhost:9201 -x "source" -y "target" -d https://localhost:9200 --rename="_type:type,age:myage" -u"_doc"

filter migration with range query

./esm -s https://192.168.3.98:9200 -m elastic:password -o json.out -x kibana_sample_data_ecommerce -q "order_date:[2020-02-01T21:59:02+00:00 TO 2020-03-01T21:59:02+00:00]"

range query, keyword type and escape

./esm -s https://192.168.3.98:9200 -m test:123 -o 1.txt -x test1  -q "@timestamp.keyword:[\"2021-01-17 03:41:20\" TO \"2021-03-17 03:41:20\"]"

generate testing data, if input.json contains 10 documents, the follow command will ingest 100 documents, good for testing

./bin/esm -i input.json -d  http://localhost:9201 -y target-index1  --regenerate_id  --repeat_times=10 

select source fields

 ./bin/esm -s http://localhost:9201 -x my_index -o dump.json --fields=author,title

rename fields while do bulk indexing

./bin/esm -i dump.json -d  http://localhost:9201 -y target-index41  --rename=title:newtitle

user buffer_count to control memory used by ESM, and use gzip to compress network traffic

./esm -s https://localhost:8000 -d https://localhost:8000 -x logs1kw -y logs122 -m elastic:medcl123 -n elastic:medcl123 --regenerate_id -w 20 --sliced_scroll_size=60 -b 5 --buffer_count=1000000 --compress false 

Download

Releases · medcl/esm · GitHub

Compile:

if download version is not fill you environment,you may try to compile it yourself. go required.

make build

  • go version >= 1.7

Options

 
  1. Usage:

  2. esm [OPTIONS]

  3. Application Options:

  4. -s, --source= source elasticsearch instance, ie: http://localhost:9200

  5. -q, --query= query against source elasticsearch instance, filter data before migrate, ie: name:medcl

  6. -d, --dest= destination elasticsearch instance, ie: http://localhost:9201

  7. -m, --source_auth= basic auth of source elasticsearch instance, ie: user:pass

  8. -n, --dest_auth= basic auth of target elasticsearch instance, ie: user:pass

  9. -c, --count= number of documents at a time: ie "size" in the scroll request (10000)

  10. --buffer_count= number of buffered documents in memory (100000)

  11. -w, --workers= concurrency number for bulk workers (1)

  12. -b, --bulk_size= bulk size in MB (5)

  13. -t, --time= scroll time (1m)

  14. --sliced_scroll_size= size of sliced scroll, to make it work, the size should be > 1 (1)

  15. -f, --force delete destination index before copying

  16. -a, --all copy indexes starting with . and _

  17. --copy_settings copy index settings from source

  18. --copy_mappings copy index mappings from source

  19. --shards= set a number of shards on newly created indexes

  20. -x, --src_indexes= indexes name to copy,support regex and comma separated list (_all)

  21. -y, --dest_index= indexes name to save, allow only one indexname, original indexname will be used if not specified

  22. -u, --type_override= override type name

  23. --green wait for both hosts cluster status to be green before dump. otherwise yellow is okay

  24. -v, --log= setting log level,options:trace,debug,info,warn,error (INFO)

  25. -o, --output_file= output documents of source index into local file

  26. -i, --input_file= indexing from local dump file

  27. --input_file_type= the data type of input file, options: dump, json_line, json_array, log_line (dump)

  28. --source_proxy= set proxy to source http connections, ie: http://127.0.0.1:8080

  29. --dest_proxy= set proxy to target http connections, ie: http://127.0.0.1:8080

  30. --refresh refresh after migration finished

  31. --fields= filter source fields, comma separated, ie: col1,col2,col3,...

  32. --rename= rename source fields, comma separated, ie: _type:type, name:myname

  33. -l, --logstash_endpoint= target logstash tcp endpoint, ie: 127.0.0.1:5055

  34. --secured_logstash_endpoint target logstash tcp endpoint was secured by TLS

  35. --repeat_times= repeat the data from source N times to dest output, use align with parameter regenerate_id to amplify the data size

  36. -r, --regenerate_id regenerate id for documents, this will override the exist document id in data source

  37. --compress use gzip to compress traffic

  38. -p, --sleep= sleep N seconds after finished a bulk request (-1)

  39. Help Options:

  40. -h, --help Show this help message

 FAQ

  • Scroll ID too long, update elasticsearch.yml on source cluster.
 
  1. http.max_header_size: 16k

  2. http.max_initial_line_length: 8k


 

 
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/843765.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C 基础环境配置(vscode || vs)

目录 一.发展 二. 环境设置 1.vs2022 2.vscode (1.)首先下载VsCode (2)安装vsCode插件 (3)下载MinGW-W64 (4)配置文件 (5)注意把里面配置的:mingw64路径改为自己的路径 (6)示例代码 三.总结 一.发展 编程语言的发展 机器语言(打孔纸带编程),汇编语言,高级语言,一步步…

CASS11自定义宗地图框

1、找到CASS11的安装路径,找到如下文件夹: 2、打开【report】文件夹,如下: 3、打开其中一个压缩包,如【标准宗地图】压缩包,结果如下: 4、打开后,将其另存为到桌面,随后关…

MySQL(三)查询

1、单表和多表查询 1.1 算术运算符、比较运算符及特殊运算符 1)MySQL的算术运算符 select 0.1+0.3333,0.1-0.3333,0.1*0.3333,1/2,1%2; select 1/0,100%0; select 3%2,mod(3,2); 2)MySQL的比较运算符 select 1=0,1=1,null=null; select 1<>0,1<>1,null<&…

seata源码分析(02)_AT和TCC基础示例

本文介绍一下如何使用seata api实现AT、TCC模式的分布式事务。 AT模式示例 启动seata-server服务 在 (02)_源码启动seata-server服务 中。 创建undo日志表 script/client/at/db/mysql.sql 文件: -- for AT mode you must to init this sql for you business database. -…

三层交换机基本配置,动态路由链接

<Huawei>system-view //进入系统视图[Huawei]undo info-center enable //关日志[Huawei]vlan batch 2 3 //创建vlan2与3[Huawei]display vlan //检查[Huawei]interface GigabitEthernet 0/0/2 //进2口[Huawei-GigabitEthernet0/0/2]port link-type access //配置…

Redis教程(十七):Redis的Redisson分布式锁

传送门:Redis教程汇总篇,让你从入门到精通 Redis分布式锁 Redis分布式锁的主要作用是在分布式系统环境下提供一种机制,用于确保在同一时间只有一个进程(或线程)能够执行某个关键代码段或访问特定的资源。这主要用于控制对共享资源的并发访问,以避免因多个进程同时修改同…

C语言 | Leetcode C语言题解之第117题填充每个节点的下一个右侧节点指针II

题目&#xff1a; 题解&#xff1a; void handle(struct Node **last, struct Node **p, struct Node **nextStart) {if (*last) {(*last)->next *p;}if (!(*nextStart)) {*nextStart *p;}*last *p; }struct Node *connect(struct Node *root) {if (!root) {return NULL…

开源博客项目Blog .NET Core源码学习(29:App.Hosting项目结构分析-17)

本文学习并分析App.Hosting项目中后台管理页面的按钮管理页面。   按钮管理页面用于显示、新建、编辑、删除页面按钮数据&#xff0c;以便配置后台管理页面中每个页面的工具栏、操作栏、数据列中的按钮的事件及响应url。按钮管理页面附带一新建及编辑页面&#xff0c;以支撑新…

Unity之如何使用Localization来实现文本+资源多语言

前言 使用Unity实现本地化&#xff08;Localization&#xff09;功能 在当今的游戏开发中&#xff0c;支持多语言已成为一项基本需求。Unity作为主流的游戏开发引擎&#xff0c;提供了强大的本地化工具&#xff0c;使开发者能够方便地为游戏添加多语言支持。本文将介绍如何在U…

从0开始学会做标书:新手学习做标书制作必修(95节课)

入门框架 电子标书 商务标书 文档排版 技术标书 实操演示 你是否也有同样的问题 1、做标书公司没人教、没人带? 2、如何看懂招标文件? 3、小白零基础能不能学习做标书? 4、商务标、技术标如何得高分? 5、做标书需要什么软件? 6、如何制作电子标书? 7、如何避…

Vue2 基础六前端工程化

代码下载 模块化相关规范 传统开发模式的主要问题&#xff1a;命名冲突、文件依赖。 模块化就是把单独的一个功能封装到一个模块&#xff08;文件&#xff09;中&#xff0c;模块之间相互隔离&#xff0c;但是可以通过特定的接口公开内部成员&#xff0c;也可以依赖别的模块…

Java核心: 使用asm操作字节码

在上一篇<Java核心: 注解处理器>中我们提到&#xff0c;通过实现AbstractProcessor&#xff0c;并调用javac -processor能够生成代码来实现特殊逻辑。不过它存在两个明显的问题: 只能新增源文件来扩展逻辑&#xff0c;无法修改现有的类或方法 必须有一个单独的编译过程&a…

三步走,Halo DB 安装指引

前文介绍了国产数据库新星 Halo 数据库是什么&#xff0c; 哈喽&#xff0c;国产数据库&#xff01;Halo DB! ★ HaloDB是基于原生PG打造的新一代高性能安全自主可控全场景通用型统一数据库。 业内首次创造性的提出插件式内核架构设计&#xff0c;通过配置的方式&#xff0c;适…

国产卫星星座,为什么一定要“走出去”?

今天这篇文章&#xff0c;我们来聊聊卫星和星座。 2024年行将过半&#xff0c;全球卫星通信产业的发展&#xff0c;又有了新的变化。 在卫星星座方面&#xff0c;各大企业的竞争博弈全面进入白热化阶段。卫星的发射速度在不断加快&#xff0c;而全球星座项目的数量和规模也在持…

如何在生产环境中以非 Root 用户启动 Kafka

目录 如何在生产环境中以非 Root 用户启动 Kafka1. 创建 Kafka 用户2. 设置目录权限3. 配置 systemd 服务文件4. 启动和启用 Kafka 服务5. 验证 Kafka 服务经验总结 为了在生产环境中以非 root 用户&#xff08;如 kafka 用户&#xff09;启动 Kafka&#xff0c;您需要确保 Ka…

为什么建立数据库连接耗时?究竟耗时多久?

数据库连接从连接池中取这已经是大家的共识了&#xff0c;因为频繁的建立或者关闭连接代价太大&#xff0c;那么代价究竟有多大&#xff1f; 我们先准备一个简单的数据库连接代码段 public static void main(String[] args) throws ClassNotFoundException, SQLException, Int…

秋招突击——算法打卡——5/27——复习{寻找特定中位数}——新做:{最长回文字串、Z 字形变换}

文章目录 复习——寻找特定中位数新作——最长回文子串个人思路分析实现代码参考学习和上述思路相同&#xff0c;枚举中心点字符串哈希二分 新作——Z 字形变换个人做法思路分析实现代码 参考解法分析总结 复习——寻找特定中位数 第一次的链接&#xff1a;寻找中位数本来以为…

Ai终点站,全系统商业闭环矩阵打造,帮电商、实体降70%成本,12款Ai联合深度实战

说白了&#xff0c;你之前5个人的团队&#xff0c;当团队人数不变的情况下&#xff0c;借助于ChatGPT和各种软件的结合&#xff0c;赋能电商直播带货&#xff0c;可以让之前一年销售额2.000万变成2.500万或者是3.000万&#xff0c;这就是这套课程的核心作用: 【1】系统课程从1…

深度神经网络——贝叶斯与朴素贝叶斯定理

概述 贝叶斯定理是概率论中一个非常重要的概念&#xff0c;它提供了一种在已知某些相关事件的概率时&#xff0c;计算另一个事件发生概率的方法。在你提供的内容中&#xff0c;贝叶斯定理被描述为一种“魔法”&#xff0c;因为它能够使计算机通过分析大量的数据来预测人们可能…

100个 Unity小游戏系列七 -Unity 抽奖游戏专题五 刮刮乐游戏

一、演示效果 二、知识点讲解 2.1 布局 void CreateItems(){var rewardLists LuckyManager.Instance.CalculateRewardId(rewardDatas, Random.Range(4, 5));reward_data_list reward_data_list ?? new List<RewardData>();reward_data_list.Clear();for (int i 0; …