ElasticSearch: Unassigned Shards, how to fix?

前端 未结 24 1213
悲&欢浪女
悲&欢浪女 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:35

    When dealing with corrupted shards you can set the replication factor to 0 and then set it back to the original value. This should clear up most if not all your corrupted shards and relocate the new replicas in the cluster.

    Setting indexes with unassigned replicas to use a replication factor of 0:

    curl -XGET http://localhost:9200/_cat/shards |\
      grep UNASSIGNED | grep ' r ' |\
      awk '{print $1}' |\
      xargs -I {} curl -XPUT http://localhost:9200/{}/_settings -H "Content-Type: application/json" \
      -d '{ "index":{ "number_of_replicas": 0}}'
    

    Setting them back to 1:

    curl -XGET http://localhost:9200/_cat/shards |\
      awk '{print $1}' |\
      xargs -I {} curl -XPUT http://localhost:9200/{}/_settings -H "Content-Type: application/json" \
      -d '{ "index":{ "number_of_replicas": 1}}'
    

    Note: Do not run this if you have different replication factors for different indexes. This would hardcode the replication factor for all indexes to 1.

提交回复
热议问题