#!/bin/bash
#源es
ES_HOST="192.168.137.200"
ES_USER=""
ES_PASSWORD=''
###获取es索引列表
index_list=`curl -u ES_USER:ES_PASSWORD -XGET "http://$ES_HOST:9200/_cat/indices?v"|awk -F' ' '{if (NR>1){print $3}}' |egrep -v "^\."`
#目的es
DES_HOST="192.168.137.200"
DES_USER="lanxin"
DES_PASSWORD='lanxin119'
###遍历列表
for index in $index_list;do
###开始执行reindex
echo -e "\n$(date '+%Y-%m-%d %H:%M:%S'), 索引$index,开始reindex"
curl -POST -H "Content-Type: application/json" -s -u $DES_USER:$DES_PASSWORD "http://$DES_HOST:9210/_reindex" -d '
{
"conflicts": "proceed",
"source": {
"remote": {
"host": "http://192.168.137.200:9200",
"username": "",
"password": "",
"socket_timeout": "30s",
"connect_timeout": "30s"
},
"index": "'$index'"
},
"dest": {
"index": "'$index'"
}
}'
echo -e "\n$(date '+%Y-%m-%d %H:%M:%S'), 索引$_index,reindex完成"
done