Created
June 30, 2015 11:32
-
-
Save innovia/a4ad63c1844ae194e5d9 to your computer and use it in GitHub Desktop.
ElasticSaerch unassigned shards reassign
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
es_cluster = 'http://localhost:9200' | |
master_node = "Howard the Duck" # sey your master node name here | |
unassigned_shards_info = `curl -s -XGET #{es_cluster}/_cat/shards | grep UNASSIGNED `.split("\n") | |
shard_indexes = [] | |
unassigned_shards_info.inject(shard_indexes){|acc, index| | |
shard = index.split(" ") | |
shard_data ||= {} | |
shard_data[shard.first] = shard[1] | |
acc << shard_data | |
} | |
puts "total unassiged shards: #{unassigned_shards_info.size}" | |
shard_indexes.each {|shard_info| | |
shard_info.each {|index, shard| | |
puts "reassigning shard no: #{shard} with index #{index} to #{node}" | |
payload = {"commands"=> [{"allocate"=>{"index"=>"#{index}", "shard"=>"#{shard}", "node"=>"#{node}", "allow_primary"=>true}}]} | |
result = `curl -s -XPOST #{es_cluster}/_cluster/reroute -d '#{payload.to_json}'` | |
} | |
sleep 1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment