I wanted to drop all shards from a single host from my Solr cluster (didn't care about losing the data) and do a little spring cleaning. To open a command-line interface with ZK:
/path/to/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
Then simply:
get /clusterstate.json
Place that content into a local file. After backing up the original content, make your edits. For instance, to drop the dead nodes, delete JSON elements with "down" states:
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
"collection":{ | |
"shards":{"shard1":{ | |
"range":null, | |
"state":"active", | |
"replicas":{ | |
"XXX.XX.X.XX:8983_solr_collection_shard1_replica1":{ | |
"state":"down", | |
"core":"collection_shard1_replica1", | |
"node_name":"XXX.XX.X.XX:8983_solr", | |
"base_url":"http://XXX.XX.X.XX:8983/solr"}, | |
"XXX.XX.X.XX:8983_solr_collection_shard1_replica1":{ | |
"state":"active", | |
"core":"collection_shard1_replica1", | |
"node_name":"XXX.XX.X.XX:8983_solr", | |
"base_url":"http://XXX.XX.X.XX:8983/solr", | |
"leader":"true"}}}}, |
To upload your new clusterstate.json (no need to halt services):
/path/to/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181 set /clusterstate.json "`cat /local/path/to/clusterstate.json`"