Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Troubleshooting

Diagnose unassigned shards

There are multiple reasons why shards might get unassigned, ranging from misconfigured allocation settings to lack of disk space.

In order to diagnose the unassigned shards in your deployment use the following steps:

In order to diagnose the unassigned shards, follow the next steps:

Use Kibana

  1. Log in to the Elastic Cloud console.
  2. On the Elasticsearch Service panel, click the name of your deployment.

    If the name of your deployment is disabled your Kibana instances might be unhealthy, in which case please contact Elastic Support. If your deployment doesn’t include Kibana, all you need to do is enable it first.

  3. Open your deployment’s side navigation menu (placed under the Elastic logo in the upper left corner) and go to Dev Tools > Console.

    Kibana Console
  4. View the unassigned shards using the cat shards API.

    resp = client.cat.shards(
        v=True,
        h="index,shard,prirep,state,node,unassigned.reason",
        s="state",
    )
    print(resp)
    response = client.cat.shards(
      v: true,
      h: 'index,shard,prirep,state,node,unassigned.reason',
      s: 'state'
    )
    puts response
    const response = await client.cat.shards({
      v: "true",
      h: "index,shard,prirep,state,node,unassigned.reason",
      s: "state",
    });
    console.log(response);
    GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state

    The response will look like this:

    [
      {
        "index": "my-index-000001",
        "shard": "0",
        "prirep": "p",
        "state": "UNASSIGNED",
        "node": null,
        "unassigned.reason": "INDEX_CREATED"
      }
    ]

    Unassigned shards have a state of UNASSIGNED. The prirep value is p for primary shards and r for replicas.

    The index in the example has a primary shard unassigned.

  5. To understand why an unassigned shard is not being assigned and what action you must take to allow Elasticsearch to assign it, use the cluster allocation explanation API.

    resp = client.cluster.allocation_explain(
        index="my-index-000001",
        shard=0,
        primary=True,
    )
    print(resp)
    response = client.cluster.allocation_explain(
      body: {
        index: 'my-index-000001',
        shard: 0,
        primary: true
      }
    )
    puts response
    const response = await client.cluster.allocationExplain({
      index: "my-index-000001",
      shard: 0,
      primary: true,
    });
    console.log(response);
    GET _cluster/allocation/explain
    {
      "index": "my-index-000001", 
      "shard": 0, 
      "primary": true 
    }

    The index we want to diagnose.

    The unassigned shard ID.

    Indicates that we are diagnosing a primary shard.

    The response will look like this:

    {
      "index" : "my-index-000001",
      "shard" : 0,
      "primary" : true,
      "current_state" : "unassigned",                 
      "unassigned_info" : {
        "reason" : "INDEX_CREATED",                   
        "at" : "2022-01-04T18:08:16.600Z",
        "last_allocation_status" : "no"
      },
      "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" : "8qt2rY-pT6KNZB3-hGfLnw",
          "node_name" : "node-0",
          "transport_address" : "127.0.0.1:9401",
          "roles": ["data_content", "data_hot"],
          "node_attributes" : {},
          "node_decision" : "no",                     
          "weight_ranking" : 1,
          "deciders" : [
            {
              "decider" : "filter",                   
              "decision" : "NO",
              "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]"  
            }
          ]
        }
      ]
    }

    The current state of the shard.

    The reason for the shard originally becoming unassigned.

    Whether to allocate the shard.

    Whether to allocate the shard to the particular node.

    The decider which led to the no decision for the node.

    An explanation as to why the decider returned a no decision, with a helpful hint pointing to the setting that led to the decision.

  6. The explanation in our case indicates the index allocation configurations are not correct. To review your allocation settings, use the get index settings and cluster get settings APIs.

    resp = client.indices.get_settings(
        index="my-index-000001",
        flat_settings=True,
        include_defaults=True,
    )
    print(resp)
    
    resp1 = client.cluster.get_settings(
        flat_settings=True,
        include_defaults=True,
    )
    print(resp1)
    response = client.indices.get_settings(
      index: 'my-index-000001',
      flat_settings: true,
      include_defaults: true
    )
    puts response
    
    response = client.cluster.get_settings(
      flat_settings: true,
      include_defaults: true
    )
    puts response
    const response = await client.indices.getSettings({
      index: "my-index-000001",
      flat_settings: "true",
      include_defaults: "true",
    });
    console.log(response);
    
    const response1 = await client.cluster.getSettings({
      flat_settings: "true",
      include_defaults: "true",
    });
    console.log(response1);
    GET my-index-000001/_settings?flat_settings=true&include_defaults=true
    
    GET _cluster/settings?flat_settings=true&include_defaults=true
  7. Change the settings using the update index settings and cluster update settings APIs to the correct values in order to allow the index to be allocated.

For more guidance on fixing the most common causes for unassinged shards please follow this guide or contact Elastic Support.

In order to diagnose the unassigned shards follow the next steps:

  1. View the unassigned shards using the cat shards API.

    resp = client.cat.shards(
        v=True,
        h="index,shard,prirep,state,node,unassigned.reason",
        s="state",
    )
    print(resp)
    response = client.cat.shards(
      v: true,
      h: 'index,shard,prirep,state,node,unassigned.reason',
      s: 'state'
    )
    puts response
    const response = await client.cat.shards({
      v: "true",
      h: "index,shard,prirep,state,node,unassigned.reason",
      s: "state",
    });
    console.log(response);
    GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state

    The response will look like this:

    [
      {
        "index": "my-index-000001",
        "shard": "0",
        "prirep": "p",
        "state": "UNASSIGNED",
        "node": null,
        "unassigned.reason": "INDEX_CREATED"
      }
    ]

    Unassigned shards have a state of UNASSIGNED. The prirep value is p for primary shards and r for replicas.

    The index in the example has a primary shard unassigned.

  2. To understand why an unassigned shard is not being assigned and what action you must take to allow Elasticsearch to assign it, use the cluster allocation explanation API.

    resp = client.cluster.allocation_explain(
        index="my-index-000001",
        shard=0,
        primary=True,
    )
    print(resp)
    response = client.cluster.allocation_explain(
      body: {
        index: 'my-index-000001',
        shard: 0,
        primary: true
      }
    )
    puts response
    const response = await client.cluster.allocationExplain({
      index: "my-index-000001",
      shard: 0,
      primary: true,
    });
    console.log(response);
    GET _cluster/allocation/explain
    {
      "index": "my-index-000001", 
      "shard": 0, 
      "primary": true 
    }

    The index we want to diagnose.

    The unassigned shard ID.

    Indicates that we are diagnosing a primary shard.

    The response will look like this:

    {
      "index" : "my-index-000001",
      "shard" : 0,
      "primary" : true,
      "current_state" : "unassigned",                 
      "unassigned_info" : {
        "reason" : "INDEX_CREATED",                   
        "at" : "2022-01-04T18:08:16.600Z",
        "last_allocation_status" : "no"
      },
      "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" : "8qt2rY-pT6KNZB3-hGfLnw",
          "node_name" : "node-0",
          "transport_address" : "127.0.0.1:9401",
          "roles": ["data_content", "data_hot"]
          "node_attributes" : {},
          "node_decision" : "no",                     
          "weight_ranking" : 1,
          "deciders" : [
            {
              "decider" : "filter",                   
              "decision" : "NO",
              "explanation" : "node does not match index setting [index.routing.allocation.include] filters [_name:\"nonexistent_node\"]"  
            }
          ]
        }
      ]
    }

    The current state of the shard.

    The reason for the shard originally becoming unassigned.

    Whether to allocate the shard.

    Whether to allocate the shard to the particular node.

    The decider which led to the no decision for the node.

    An explanation as to why the decider returned a no decision, with a helpful hint pointing to the setting that led to the decision.

  3. The explanation in our case indicates the index allocation configurations are not correct. To review your allocation settings, use the get index settings and cluster get settings APIs.

    resp = client.indices.get_settings(
        index="my-index-000001",
        flat_settings=True,
        include_defaults=True,
    )
    print(resp)
    
    resp1 = client.cluster.get_settings(
        flat_settings=True,
        include_defaults=True,
    )
    print(resp1)
    response = client.indices.get_settings(
      index: 'my-index-000001',
      flat_settings: true,
      include_defaults: true
    )
    puts response
    
    response = client.cluster.get_settings(
      flat_settings: true,
      include_defaults: true
    )
    puts response
    const response = await client.indices.getSettings({
      index: "my-index-000001",
      flat_settings: "true",
      include_defaults: "true",
    });
    console.log(response);
    
    const response1 = await client.cluster.getSettings({
      flat_settings: "true",
      include_defaults: "true",
    });
    console.log(response1);
    GET my-index-000001/_settings?flat_settings=true&include_defaults=true
    
    GET _cluster/settings?flat_settings=true&include_defaults=true
  4. Change the settings using the update index settings and cluster update settings APIs to the correct values in order to allow the index to be allocated.

For more guidance on fixing the most common causes for unassinged shards please follow this guide.

See this video for a walkthrough of monitoring allocation health.

If you’re using Elastic Cloud Hosted, then you can use AutoOps to monitor your cluster. AutoOps significantly simplifies cluster management with performance recommendations, resource utilization visibility, real-time issue detection and resolution paths. For more information, refer to Monitor with AutoOps.

© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/diagnose-unassigned-shards.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API