Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divyam-goel/78aeae31a72c893798987bcb86b56bce to your computer and use it in GitHub Desktop.
Save divyam-goel/78aeae31a72c893798987bcb86b56bce to your computer and use it in GitHub Desktop.
elasticsearch trying to allocate a primary shard which is disabled

Allow routing allocations:

curl -XPUT localhost:9200/_cluster/settings -d '{
                "transient" : {
                    "cluster.routing.allocation.enable" : "all"
                }
        }'

Reallocate unassigned shards, allowing primary allocations:

curl -s localhost:9200/_cat/shards | grep UNASS | while read line ; do \
  read -a fields <<<"$line" ;
  curl -XPOST -d '{ 
    "commands" : [ 
      { 
        "allocate" : {
          "index" : "'${fields[0]}'",
          "shard" : '${fields[1]}',
          "node" : "elasticsearch-'$(hostname)'",
          "allow_primary": "true"
        }
      }
    ]
  }' http://localhost:9200/_cluster/reroute?pretty ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment