How can I delete unnassigned shards?

In my cluster there are unassigned shards which are not primary shards.
I don't know why I have these secondary shards in my cluster. I didn't create them intentionally and I use the default configuration (elasticsearch.yml). How can I delete these unnassigned shards? (without deleting the primary shard)

GET _cluster/allocation/explain?pretty
{
  "index": "0001.metadata",
  "shard": 0,
  "primary": false
}
{
  "index" : "0001.metadata",
  "shard" : 0,
  "primary" : false,
  "current_state" : "unassigned",
  "unassigned_info" : {
    "reason" : "CLUSTER_RECOVERED",
    "at" : "2023-03-10T07:22:54.916Z",
    "last_allocation_status" : "no_attempt"
  },
  "can_allocate" : "no",
  "allocate_explanation" : "Elasticsearch isn't allowed to allocate this shard to any of the nodes in the cluster. Choose a node to which you expect this shard to be allocated, find this node in the node-by-node explanation, and address the reasons which prevent Elasticsearch from allocating this shard there.",
  "node_allocation_decisions" : [
    {
      "node_id" : "4S9PhH2FQymVIe3tysYpww",
      "node_name" : "FM11L",
      "transport_address" : "127.0.0.1:9300",
      "node_attributes" : {
        "ml.max_jvm_size" : "17037262848",
        "xpack.installed" : "true",
        "ml.machine_memory" : "34069057536"
      },
      "node_decision" : "no",
      "deciders" : [
        {
          "decider" : "same_shard",
          "decision" : "NO",
          "explanation" : "a copy of this shard is already allocated to this node [[0001.metadata][0], node[4S9PhH2FQymVIe3tysYpww], [P], s[STARTED], a[id=e6Kbv9aSQt6LaHlnf023sg]]"
        }
      ]
    }
  ]
}

I found a solution for my problem.

I set

PUT _settings
{
  "index.number_of_replicas": 0
}

And so I got the health status green.

Also I find
https://www.cyberithub.com/how-to-delete-elasticsearch-unassigned-shards/

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.