Skip to content

Elasticsearch UNASSIGNED shards

Case 1

$ curl localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host      ip        node
    97        2.2gb    39.2gb     29.4gb     68.7gb           57 10.0.1.1  10.0.1.1  es-cluster
   192                                                                               UNASSIGNED

Check other values

curl localhost:9200/_cluster/health?pretty

curl -s localhost:9200/_cat/shards | grep INIT

curl -s localhost:9200/_cluster/allocation/explain?pretty

curl localhost:9200/_nodes/hot_threads

Fix 1

curl -X PUT 'http://localhost:9200/_all/_settings' -H 'Content-Type: application/json' \
-d '{"blocks.read_only_allow_delete": null}' 

curl -X PUT localhost:9200/_settings -H 'Content-Type: application/json' -d '{"index":{"number_of_replicas":0}}'

# for cluster with 3 data nodes
curl -X PUT localhost:9200/_settings -H 'Content-Type: application/json' -d '{"index":{"number_of_replicas":2}}'

curl -X PUT localhost:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d' {"persistent": {"cluster.routing.allocation.enable": "all"} }

Case 2 UNASSIGNED CLUSTER_RECOVERED

Symptoms:

# curl localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 33,
  "active_shards" : 33,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 3,
  "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" : 91.66666666666666
}


# curl -s 'localhost:9200/_cat/shards?v=true&h=index,id,shard,prirep,state,node,unassigned.reason&s=state'

index                                                              id                     shard prirep state      node         unassigned.reason
.ds-logs-generic-default-2023.01.10-000001                                                0     r      UNASSIGNED              CLUSTER_RECOVERED
foo-bar.2023-01                                                                           0     r      UNASSIGNED              CLUSTER_RECOVERED
foo-web.2023-01                                                                           0     r      UNASSIGNED              CLUSTER_RECOVERED
.internal.alerts-transform.health.alerts-default-000001            zC3US6BJT0OZbl5UGIaCMw 0     p      STARTED    0bac5229fcd8 
.ds-.kibana-event-log-ds-2023.01.09-000001                         zC3US6BJT0OZbl5UGIaCMw 0     p      STARTED    0bac5229fcd8 
...

Check

curl -XGET 'http://localhost:9200/_cluster/allocation/explain?pretty'

Fix

curl -XPUT -H 'Content-Type: application/json' 'localhost:9200/--INDEX--/_settings' -d '{ "number_of_replicas" : 0 }'