ElasticSearch: Unassigned Shards, how to fix?

前端 未结 24 1185
悲&欢浪女
悲&欢浪女 2020-12-04 05:03

I have an ES cluster with 4 nodes:

number_of_replicas: 1
search01 - master: false, data: false
search02 - master: true, data: true
search03 - master: false,          


        
24条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 05:39

    I've stuck today with the same issue of shards allocation. The script that W. Andrew Loe III has proposed in his answer didn't work for me, so I modified it a little and it finally worked:

    #!/usr/bin/env bash
    
    # The script performs force relocation of all unassigned shards, 
    # of all indices to a specified node (NODE variable)
    
    ES_HOST=""
    NODE=""
    
    curl ${ES_HOST}:9200/_cat/shards > shards
    grep "UNASSIGNED" shards > unassigned_shards
    
    while read LINE; do
      IFS=" " read -r -a ARRAY <<< "$LINE"
      INDEX=${ARRAY[0]}
      SHARD=${ARRAY[1]}
    
      echo "Relocating:"
      echo "Index: ${INDEX}"
      echo "Shard: ${SHARD}"
      echo "To node: ${NODE}"
    
      curl -s -XPOST "${ES_HOST}:9200/_cluster/reroute" -d "{
        \"commands\": [
           {
             \"allocate\": {
               \"index\": \"${INDEX}\",
               \"shard\": ${SHARD},
               \"node\": \"${NODE}\",
               \"allow_primary\": true
             }
           }
         ]
      }"; echo
      echo "------------------------------"
    done 

    Now, I'm not kind of a Bash guru, but the script really worked for my case. Note, that you'll need to specify appropriate values for "ES_HOST" and "NODE" variables.

提交回复
热议问题