Disabling shard allocation prevents Elasticsearch from relocating shards while nodes are being restarted or taken out of service, reducing recovery churn and avoiding unnecessary disk and network I/O during maintenance.

Shard placement is controlled by the dynamic cluster setting cluster.routing.allocation.enable, applied through the Cluster Settings API at /_cluster/settings. The setting affects the entire cluster immediately and supports several modes that control allocation and relocation behavior.

Leaving allocation disabled can keep replicas unassigned and lower fault tolerance until allocation is restored. Secured clusters often require https, authentication, and a trusted CA bundle for API calls, so endpoints and curl options may differ from local examples.

Steps to disable and enable shard allocation in Elasticsearch:

  1. Check the current shard allocation mode.
    $ curl -sS "http://localhost:9200/_cluster/settings?include_defaults=true&filter_path=defaults.cluster.routing.allocation.enable,persistent.cluster.routing.allocation.enable,transient.cluster.routing.allocation.enable&pretty"
    {
      "defaults" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "all"
            }
          }
        }
      }
    }

    persistent or transient values override the defaults value shown in the response.

  2. Disable shard allocation for the cluster.
    $ curl -sS -H "Content-Type: application/json" -X PUT "http://localhost:9200/_cluster/settings" -d '{
      "persistent": {
        "cluster.routing.allocation.enable": "none"
      }
    }'
    {"acknowledged":true,"persistent":{"cluster":{"routing":{"allocation":{"enable":"none"}}}},"transient":{}}

    Replica recovery and relocations remain paused while allocation is none, which can leave the cluster under-replicated until allocation is restored.

  3. Verify shard allocation is disabled.
    $ curl -sS "http://localhost:9200/_cluster/settings?include_defaults=true&filter_path=defaults.cluster.routing.allocation.enable,persistent.cluster.routing.allocation.enable,transient.cluster.routing.allocation.enable&pretty"
    {
      "persistent" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "none"
            }
          }
        }
      }
    }

    primaries disables replica allocation while still allowing primary shard allocation when required.

  4. Re-enable shard allocation by clearing the override.
    $ curl -sS -H "Content-Type: application/json" -X PUT "http://localhost:9200/_cluster/settings" -d '{
      "persistent": {
        "cluster.routing.allocation.enable": null
      }
    }'
    {"acknowledged":true,"persistent":{},"transient":{}}

    Setting the value to null removes the explicit persistent override and returns to the default behavior (typically all).

  5. Verify shard allocation is enabled.
    $ curl -sS "http://localhost:9200/_cluster/settings?include_defaults=true&filter_path=defaults.cluster.routing.allocation.enable,persistent.cluster.routing.allocation.enable,transient.cluster.routing.allocation.enable&pretty"
    {
      "defaults" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "all"
            }
          }
        }
      }
    }
  6. Check cluster health for shard recovery progress.
    $ curl -sS "http://localhost:9200/_cluster/health?pretty"
    {
      "cluster_name" : "search-cluster",
      "status" : "yellow",
      "timed_out" : false,
      "number_of_nodes" : 1,
      "number_of_data_nodes" : 1,
      "active_primary_shards" : 4,
      "active_shards" : 4,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 1,
      "delayed_unassigned_shards" : 0,
      "number_of_pending_tasks" : 0,
      "number_of_in_flight_fetch" : 0,
      "task_max_waiting_in_queue_millis" : 0,
      "active_shards_percent_as_number" : 80.0
    }

    yellow can be expected during recovery or when replicas cannot be assigned due to node count or allocation rules.