欢迎来到ArchitecTang的博客

Elasticsearch 索引修复

Elasticsearch 7.X

点击查看代码
#!/bin/bash
master=$(curl -s 'http://172.17.89.243:9200/_cat/master?v' | grep -v ' ip ' | awk '{print $1}')
for index in $(curl  -s 'http://172.17.89.243:9200/_cat/shards' | grep UNASSIGNED | awk '{print $1}' | sort | uniq); do
    for shard in $(curl  -s 'http://172.17.89.243:9200/_cat/shards' | grep UNASSIGNED | grep $index | awk '{print $2}' | sort | uniq); do
        echo  $index $shard
        curl -XPOST -H 'Content-Type: application/json'  'http://172.17.89.243:9200/_cluster/reroute' -d '{
            "commands" : [ {
                  "allocate_empty_primary" : {
                      "index" : "'$index'",
                      "shard" : "'$shard'",
                      "node" : "'$master'",
                  "accept_data_loss" : true
                  }
                }
            ]
        }'
        sleep 1
    done
done
posted @ 2022-08-22 16:21  ArchitecTang  阅读(42)  评论(0编辑  收藏  举报