项目地址:https://github.com/elasticsearch-dump/elasticsearch-dump
1.安装nodejs (略)
2.安装elasticdump (注意需要将node的bin目录放置在PATH中)
|
npm install elasticdump -g |
3.迁移数据
|
elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=settings elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=analyzer elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=mapping elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=data ####备注########### S_ES: 源ES D_ES: 目标ES index:索引名 |
迁移整个集群脚本示例
|
#!/bin/bash S_ES="https://search-hifive-open-test-pnmiylftgjjccopkfeowpo7yue.cn-northwest-1.es.amazonaws.com.cn" D_ES="http://172.27.29.137:9200" for index in `curl -s $S_ES/_cat/indices|cut -d " " -f 3`;do echo $index elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=settings elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=analyzer elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=mapping elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=data done |
删除ES所有索引
|
#!/bin/bash ES_HOST="http://172.27.29.137:9200" read -p "删除数据不可逆,确定Y/N:" action case $action in "Y" | "y") curl -s $ES_HOST/_cat/indices |awk '{print $3}' |grep -v kibana |xargs -i curl -XDELETE $ES_HOST/{} ;; "N" | "n") echo "no" ;; *) echo "识别Y N失败" esac |