Skip to content

Instantly share code, notes, and snippets.

@wags
Last active December 29, 2015 20:30
Show Gist options
  • Save wags/d5feb35f20b56b3f52ca to your computer and use it in GitHub Desktop.
Save wags/d5feb35f20b56b3f52ca to your computer and use it in GitHub Desktop.
Elasticsearch snippet for disabling / enabling shard reallocation. Useful when performing a rolling restart of the cluster, like during an upgrade.

Use this code before performing a rolling restart of an Elasticsearch cluster. The transient field means that the setting will be reset the next time Elasticsearch is restarted on the node.

Disable

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.enable": "none"
  }
}

The response should look like this:

{
  "acknowledged": true,
  "persistent": {},
  "transient": {
    "cluster": {
      "routing": {
        "allocation": {
          "enable": "none"
        }
      }
    }
  }
}

Now, if any data nodes are rebooted, the shards will not attempt to rebalance.

Enable

To turn it back on, use:

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.enable": "all"
  }
}

The response will look like this:

{
  "acknowledged": true,
  "persistent": {},
  "transient": {
    "cluster": {
      "routing": {
        "allocation": {
          "enable": "all"
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment