Saturday, August 24, 2013

Manually editing Solr's clusterstate.json on Zookeeper

There will probably come a time when you want to do something not readily covered in Solr's APIs.  Manually editing the clusterstate.json is easy to do but should be approached with caution.

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/ -server

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:

To upload your new clusterstate.json (no need to halt services):

/path/to/zookeeper/bin/ -server set /clusterstate.json "`cat /local/path/to/clusterstate.json`"


  1. Thank you, this helped a lot.
    If we change zookeeper settings like above, do we need to change Solr settings manually? If so how can we do it.
    Currently I changed leader settings in Zookeeper but Solr is reporting its not the Leader.

    1. Sorry, never tried to change the leader manually so I don't know. I used to worry about who was the leader or the replica but then realized it didn't matter (at least for me).

  2. Uploading new clusterstate.json with

    /path/to/zookeeper/bin/ -server set /clusterstate.json "`cat /local/path/to/clusterstate.json`"

    did not work, but

    /path/to/zookeeper/bin/ -server set /clusterstate.json "$(< /local/path/to/clusterstate.json)"


  3. 谢谢,我们集群中有个分片莫名奇妙就处于recovring状态,重启之后也没有用,但是日志中并不能发现什么显著错误,按照你的方法,我们手动更新了zookeeper中clusterstate.json,好使了.