Shard rebalancing keeps Elasticsearch from drifting into uneven shard distribution after node failures, scaling events, or large index changes. A balanced cluster reduces hot nodes, evens out disk usage, and improves resilience when disruptions happen.
Elasticsearch continuously evaluates shard placement and can relocate shards between nodes to improve balance while still respecting allocation rules such as awareness and filtering. Cluster-wide rebalancing behavior is controlled by dynamic settings, including cluster.routing.rebalance.enable to select which shard types are eligible for balancing.
Shard relocations consume network and disk I/O, so restricting rebalancing can reduce churn during planned maintenance windows. Prefer persistent cluster settings for predictable behavior across restarts, since transient settings reset on restart and can clear unexpectedly on unstable clusters, and restore normal balancing as soon as possible.
Steps to configure Elasticsearch shard rebalancing:
- Check the current shard rebalancing setting.
$ curl -s "http://localhost:9200/_cluster/settings?include_defaults=true&filter_path=defaults.cluster.routing.rebalance.enable,persistent.cluster.routing.rebalance.enable,transient.cluster.routing.rebalance.enable&pretty" { "defaults" : { "cluster" : { "routing" : { "rebalance" : { "enable" : "all" } } } } }defaults shows the default value, while persistent and transient show explicit overrides, and secured clusters typically require https plus authentication.
- Disable shard rebalancing during maintenance.
$ curl -s -H "Content-Type: application/json" -X PUT "http://localhost:9200/_cluster/settings?pretty" -d '{ "persistent": { "cluster.routing.rebalance.enable": "none" } }' { "acknowledged" : true, "persistent" : { "cluster" : { "routing" : { "rebalance" : { "enable" : "none" } } } }, "transient" : { } }Valid values for cluster.routing.rebalance.enable are all, primaries, replicas, and none, and leaving it set to none can prevent the cluster from returning to an evenly balanced state.
- Re-enable shard rebalancing after maintenance.
$ curl -s -H "Content-Type: application/json" -X PUT "http://localhost:9200/_cluster/settings?pretty" -d '{ "persistent": { "cluster.routing.rebalance.enable": "all" } }' { "acknowledged" : true, "persistent" : { "cluster" : { "routing" : { "rebalance" : { "enable" : "all" } } } }, "transient" : { } }Restore the previously recorded value when it was set to primaries or replicas, or assign null to remove an explicit override and fall back to defaults.
- Verify the shard rebalancing setting is applied.
$ curl -s "http://localhost:9200/_cluster/settings?include_defaults=true&filter_path=defaults.cluster.routing.rebalance.enable,persistent.cluster.routing.rebalance.enable,transient.cluster.routing.rebalance.enable&pretty" { "persistent" : { "cluster" : { "routing" : { "rebalance" : { "enable" : "all" } } } } }
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
