zoukankan      html  css  js  c++  java
  • 利用elasticsearch-dump实现es索引数据迁移附脚本

    1、安装环境

    CentOS Linux release 7.5.1804 (Core)
    
    • 1

    2、安装nodejs

    yum install -y nodejs
    
    • 1

    3、验证nodejs

    [root@localhost yum.repos.d]# node -v
    v8.12.0
    [root@localhost yum.repos.d]# npm -v
    6.4.1
    
    • 1
    • 2
    • 3
    • 4

    4、安装elasticsearch-dump

    npm install elasticdump
    
    • 1

    5、验证安装

    进入elasticdump/bin目录下

    cd node_modules/elasticdump/bin/
    
    • 1

    执行

     ./elasticdump
    
    • 1

    出现

    Fri, 19 Oct 2018 07:03:15 GMT | Error Emitted => {"errors":["`input` is a required input","`output` is a required input"]}
    
    • 1

    报错是因为没有输入参数

    6、使用dump迁移索引

    #拷贝索引

    elasticdump 
    	--input=http://production.es.com:9200/my_index 
    	--output=http://staging.es.com:9200/my_index 
    	--type=mapping
    
    • 1
    • 2
    • 3
    • 4

    #拷贝数据

    elasticdump 
    	--input=http://production.es.com:9200/my_index 
    	--output=http://staging.es.com:9200/my_index 
    	--type=data
    
    • 1
    • 2
    • 3
    • 4

    #拷贝所有索引

    elasticdump  
    	--input=http://production.es.com:9200/ 
    	--output=http://staging.es.com:9200/ 
    	--all=true  
    
    • 1
    • 2
    • 3
    • 4

    7、迁移实战

    为了方便操作写了一个脚本,仅供参考。

    #!/bin/bash
    echo -n "源ES地址: "
    read old
    echo -n "目标ES地址: "
    read new
    echo -n "源索引名: "
    read old_index
    echo -n "目标索引名: "
    read new_index
    cd /root/node_modules/elasticdump/bin/
     ./elasticdump --input=$old/$old_index  --output=$new/$new_index  --type=mapping &>> /root/dump.log
     ./elasticdump --input=$old/$old_index  --output=$new/$new_index  --type=data &>> /root/dump.log
  • 相关阅读:
    第十一周上机练习
    JAVA第十周上机练习
    JAVA第九周上机练习
    JAVA第八周作业
    JAVA第八周上机作业
    JAVA第七周作业
    Java第七周上机练习
    Java第六周作业
    JAVA第六周上机练习
    34-指针与二维数组
  • 原文地址:https://www.cnblogs.com/agang-php/p/11611769.html
Copyright © 2011-2022 走看看