---
type: api
title: Get the search shards
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-search-shards
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-search-shards
products:
  - Elasticsearch
---

# Get the search shards


Availability:

## Paths

- `POST` (also `GET`) `/{index}/_search_shards`
- `POST` (also `GET`) `/_search_shards`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `index` (union IndexName | [] IndexName) — optional, leave it out to use `/_search_shards`
  A comma-separated list of data streams, indices, and aliases to search.
It supports wildcards (`*`).
To search all data streams and indices, omit this parameter or use `*` or `_all`.

## Description

Get the indices and shards that a search request would be run against.
This information can be useful for working out issues or planning optimizations with routing and shard preferences.
When filtered aliases are used, the filter is returned as part of the `indices` section.

If the Elasticsearch security features are enabled, you must have the `view_index_metadata` or `manage` index privilege for the target data stream, index, or alias.

## Required authorization

* Index privileges: `view_index_metadata`

## Query String Parameters

- `allow_no_indices` (boolean · default: false)
  A setting that does two separate checks on the index expression.
If `false`, the request returns an error (1) if any wildcard expression
(including `_all` and `*`) resolves to zero matching indices or (2) if the
complete set of resolved indices, aliases or data streams is empty after all
expressions are evaluated. If `true`, index expressions that resolve to no
indices are allowed and the request returns an empty result.
- `expand_wildcards` (string ExpandWildcards · default: open)
  Type of index that wildcard patterns can match.
If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.
Supports comma-separated values, such as `open,hidden`.

Supported values include:
  - `all`: Match any data stream or index, including hidden ones.
  - `open`: Match open, non-hidden indices. Also matches any non-hidden data stream.
  - `closed`: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  - `hidden`: Match hidden data streams and hidden indices. Must be combined with `open`, `closed`, or `both`.
  - `none`: Wildcard expressions are not accepted.
  Values: `all`, `open`, `closed`, `hidden`, `none`
- `ignore_unavailable` (boolean · default: false)
  If `false`, the request returns an error if it targets a concrete (non-wildcarded)
index, alias, or data stream that is missing, closed, or otherwise unavailable.
If `true`, unavailable concrete targets are silently ignored.
- `local` (boolean · default: false)
  If `true`, the request retrieves information from the local node only.
- `master_timeout` (string Duration · default: 30s)
  The period to wait for a connection to the master node.
If the master node is not available before the timeout expires, the request fails and returns an error.
IT can also be set to `-1` to indicate that the request should never timeout.
- `preference` (string)
  The node or shard the operation should be performed on.
It is random by default.
- `routing` (union Routing)
  A custom value used to route operations to a specific shard.
Not allowed when `index.slice.enabled` is `true` for the target index; use `_slice` instead.
  One of: `string` or `string[]`

## Response

`application/json`

- `nodes` (map string to SearchShardsNodeAttributes)
  Map values ({} SearchShardsNodeAttributes)
  - `name` (string)
    The human-readable identifier of the node.
  - `ephemeral_id` (string Id)
    The ephemeral ID of the node.
  - `transport_address` (string)
    The host and port where transport HTTP connections are accepted.
  - `external_id` (string)
  - `attributes` (map string to string)
    Lists node attributes.
  - `roles` (NodeRoles)
    Values: `master`, `data`, `data_cold`, `data_content`, `data_frozen`, `data_hot`, `data_warm`, `client`, `ingest`, `ml`, `voting_only`, `transform`, `remote_cluster_client`, `coordinating_only`
  - `version` (string)
  - `min_index_version` (number)
  - `max_index_version` (number)
- `shards` ([] NodeShard)
- `indices` (map string to ShardStoreIndex)
  Map values ({} ShardStoreIndex)
  - `aliases` ([] string Name)
  - `filter` ({} QueryContainer)
    See [QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/types/_types-query_dsl-querycontainer)
## Code Examples

#### Console

```console
POST /my-index-000001/_search_shards
```

#### JavaScript

```javascript
const response = await client.searchShards({
  index: "my-index-000001",
});
```

#### Python

```python
resp = client.search_shards(
    index="my-index-000001",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/my-index-000001/_search_shards" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.searchShards(s -> s
    .index("my-index-000001")
);
```

#### C#

```c#
var response = await client
    .SearchShardsAsync(d1 => d1
        .Indices(new[] { "my-index-000001" })
    );
```

#### PHP

```php
$resp = $client->searchShards([
    "index" => "my-index-000001",
]);
```

#### Ruby

```ruby
response = client.search_shards(
  index: "my-index-000001"
)
```

## Response Examples

#### Search shards response example1

An abbreviated response from `GET /my-index-000001/_search_shards`.

```json
{
  "nodes": {},
  "indices": {
      "my-index-000001": { }
  },
  "shards": [
      [
      {
          "index": "my-index-000001",
          "node": "JklnKbD7Tyqi9TP3_Q_tBg",
          "relocating_node": null,
          "primary": true,
          "shard": 0,
          "state": "STARTED",
          "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"},
          "relocation_failure_info" : {
          "failed_attempts" : 0
          }
      }
      ],
      [
      {
          "index": "my-index-000001",
          "node": "JklnKbD7Tyqi9TP3_Q_tBg",
          "relocating_node": null,
          "primary": true,
          "shard": 1,
          "state": "STARTED",
          "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"},
          "relocation_failure_info" : {
          "failed_attempts" : 0
          }
      }
      ],
      [
      {
          "index": "my-index-000001",
          "node": "JklnKbD7Tyqi9TP3_Q_tBg",
          "relocating_node": null,
          "primary": true,
          "shard": 2,
          "state": "STARTED",
          "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"},
          "relocation_failure_info" : {
          "failed_attempts" : 0
          }
      }
      ],
      [
      {
          "index": "my-index-000001",
          "node": "JklnKbD7Tyqi9TP3_Q_tBg",
          "relocating_node": null,
          "primary": true,
          "shard": 3,
          "state": "STARTED",
          "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"},
          "relocation_failure_info" : {
          "failed_attempts" : 0
          }
      }
      ],
      [
      {
          "index": "my-index-000001",
          "node": "JklnKbD7Tyqi9TP3_Q_tBg",
          "relocating_node": null,
          "primary": true,
          "shard": 4,
          "state": "STARTED",
          "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"},
          "relocation_failure_info" : {
          "failed_attempts" : 0
          }
      }
      ]
    ]
  }
```

