Type to search.

Fix error: All shards failed

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

JSON

Error: all shards failed

The all shards failed error indicates that Elasticsearch couldn't get a successful response from any of the shards involved in the query. Possible causes include shard allocation issues, misconfiguration, insufficient resources, or unsupported operations such as aggregating on text fields.

Detect and resolve issues with AutoOps

AutoOps is a monitoring tool that detects issues in your Elasticsearch cluster in real time and recommends how to resolve them and improve performance. Learn more about AutoOps.

The all shards failed error can occur when you try to sort or aggregate on text fields. These fields are designed for full-text search and don't support exact-value operations like sorting and aggregation.

To fix this issue, use a .keyword subfield:

JSON
GET my-index/_search
{
  "aggs": {
    "names": {
      "terms": {
        "field": "name.keyword"
      }
    }
  }
}

If no .keyword subfield exists, define a multi-field mapping:

JSON
PUT my-index
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

The all shards failed error can also occur when you use a metric aggregation on a text field. Metric aggregations require numeric fields.

You can use a script to convert the text value to a number at query time:

JSON
GET my-index/_search
{
  "aggs": {
    "total_cost": {
      "sum": {
        "script": {
          "source": "Integer.parseInt(doc.cost.value)"
        }
      }
    }
  }
}

Or change the field mapping to a numeric type:

JSON
PUT my-index
{
  "mappings": {
    "properties": {
      "cost": {
        "type": "integer"
      }
    }
  }
}

A shard failure during recovery can prevent successful queries.

To identify the cause, check the cluster health:

JSON
GET _cluster/health

As a last resort, you can delete the problematic index.

Global aggregations must be defined at the top level of the aggregations object. Nesting can cause errors.

To fix this issue, structure the query so that the global aggregation appears at the top level:

JSON
GET my-index/_search
{
  "size": 0,
  "aggs": {
    "all_products": {
      "global": {},
      "aggs": {
        "genres": {
          "terms": {
            "field": "cost"
          }
        }
      }
    }
  }
}

Using a reverse_nested aggregation outside of a nested context causes errors.

To fix this issue, structure the query so that the reverse_nested aggregation is inside a nested aggregation:

JSON
GET my-index/_search
{
  "aggs": {
    "comments": {
      "nested": {
        "path": "comments"
      },
      "aggs": {
        "top_usernames": {
          "terms": {
            "field": "comments.username"
          },
          "aggs": {
            "comment_issue": {
              "reverse_nested": {},
              "aggs": {
                "top_tags": {
                  "terms": {
                    "field": "tags"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Use the _cat/shards API to view shard status and troubleshoot further.

JSON
GET _cat/shards

For a specific index:

JSON
GET _cat/shards/my-index

Example output:

JSON
my-index 5 p STARTED    0  283b 127.0.0.1 ziap
my-index 5 r UNASSIGNED
my-index 2 p STARTED    1 3.7kb 127.0.0.1 ziap
my-index 2 r UNASSIGNED
my-index 3 p STARTED    3 7.2kb 127.0.0.1 ziap
my-index 3 r UNASSIGNED
my-index 1 p STARTED    1 3.7kb 127.0.0.1 ziap
my-index 1 r UNASSIGNED
my-index 4 p STARTED    2 3.8kb 127.0.0.1 ziap
my-index 4 r UNASSIGNED
my-index 0 p STARTED    0  283b 127.0.0.1 ziap
my-index 0 r UNASSIGNED