# 索引->恢复/分片存储

## Indices Recovery 索引恢复

索引恢复API提供观察正在恢复的索引分片的功能。可以针对特定的索引或者集群范围报告恢复的状态。

例如，如下命令将显示索引”index1“和”index2“的恢复信息。

```
GET index1,index2/_recovery?human
```

要查看集群的恢复状态，只需要省略索引名称。

```
GET /_recovery?human
```

响应：

```
{
  "index1" : {
    "shards" : [ {
      "id" : 0,
      "type" : "SNAPSHOT",
      "stage" : "INDEX",
      "primary" : true,
      "start_time" : "2014-02-24T12:15:59.716",
      "start_time_in_millis": 1393244159716,
      "total_time" : "2.9m",
      "total_time_in_millis" : 175576,
      "source" : {
        "repository" : "my_repository",
        "snapshot" : "my_snapshot",
        "index" : "index1"
      },
      "target" : {
        "id" : "ryqJ5lO5S4-lSFbGntkEkg",
        "hostname" : "my.fqdn",
        "ip" : "10.0.1.7",
        "name" : "my_es_node"
      },
      "index" : {
        "size" : {
          "total" : "75.4mb",
          "total_in_bytes" : 79063092,
          "reused" : "0b",
          "reused_in_bytes" : 0,
          "recovered" : "65.7mb",
          "recovered_in_bytes" : 68891939,
          "percent" : "87.1%"
        },
     "files" : {
          "total" : 73,
          "reused" : 0,
          "recovered" : 69,
          "percent" : "94.5%"
        },
        "total_time" : "0s",
        "total_time_in_millis" : 0
      },
      "translog" : {
        "recovered" : 0,
        "total" : 0,
        "percent" : "100.0%",
        "total_on_start" : 0,
        "total_time" : "0s",
        "total_time_in_millis" : 0,
      },
      "start" : {
        "check_index_time" : "0s",
        "check_index_time_in_millis" : 0,
        "total_time" : "0s",
        "total_time_in_millis" : 0
      }
    } ]
  }
}
```

以上响应内容展示了单个索引恢复单个分片。在这个例子中，恢复的源是快照存储库，恢复的目标是名称为”my\_es\_node“的节点。

除此之外，输出显示恢复的文件的数量和百分比，以及恢复的字节数和百分比。

在一些情况下，更高级别的细节可能是优选的。设置”detailed=true“将提供恢复中的物理文件列表。

```
GET _recovery?human&detailed=true
```

响应：

```
{
  "index1" : {
    "shards" : [ {
      "id" : 0,
      "type" : "STORE",
      "stage" : "DONE",
      "primary" : true,
      "start_time" : "2014-02-24T12:38:06.349",
      "start_time_in_millis" : "1393245486349",
      "stop_time" : "2014-02-24T12:38:08.464",
      "stop_time_in_millis" : "1393245488464",
      "total_time" : "2.1s",
      "total_time_in_millis" : 2115,
      "source" : {
        "id" : "RGMdRc-yQWWKIBM4DGvwqQ",
        "hostname" : "my.fqdn",
        "ip" : "10.0.1.7",
        "name" : "my_es_node"
      },
      "target" : {
        "id" : "RGMdRc-yQWWKIBM4DGvwqQ",
        "hostname" : "my.fqdn",
        "ip" : "10.0.1.7",
        "name" : "my_es_node"
      },
      "index" : {
        "size" : {
          "total" : "24.7mb",
          "total_in_bytes" : 26001617,
          "reused" : "24.7mb",
          "reused_in_bytes" : 26001617,
          "recovered" : "0b",
          "recovered_in_bytes" : 0,
          "percent" : "100.0%"
        },
  "files" : {
          "total" : 26,
          "reused" : 26,
          "recovered" : 0,
          "percent" : "100.0%",
          "details" : [ {
            "name" : "segments.gen",
            "length" : 20,
            "recovered" : 20
          }, {
            "name" : "_0.cfs",
            "length" : 135306,
            "recovered" : 135306
          }, {
            "name" : "segments_2",
            "length" : 251,
            "recovered" : 251
          },
           ...
          ]
        },
        "total_time" : "2ms",
        "total_time_in_millis" : 2
      },
      "translog" : {
        "recovered" : 71,
        "total_time" : "2.0s",
        "total_time_in_millis" : 2025
      },
      "start" : {
        "check_index_time" : 0,
        "total_time" : "88ms",
        "total_time_in_millis" : 88
      }
    } ]
  }
}
```

以上响应显示恢复的实际文件和它们大小的详细列表（为了简洁截取部分）。

还显示了恢复的各个阶段的实际时间（以毫秒为单位）:索引检索，事务日志重放以及索引开始时间。

注意，上面的列表表示恢复处于完成阶段。所有的恢复，无论是正在进行的还是已经完成的，都保持在集群状态下，并且可以随时报告。”active\_only=true“这个设置只显示正在进行的恢复。

以下是完整的选项列表：

| `detailed`    | 显示详细视图。这主要用于查看物理索引文件的恢复情况。默认为：false。 |
| ------------- | ------------------------------------ |
| `active_only` | 只显示当前正在进行的恢复。默认为：false。              |

输出字段说明：

| `id`                   | 分片id                                                                                                   |
| ---------------------- | ------------------------------------------------------------------------------------------------------ |
| `type`                 | 恢复类型:存储 、快照、副本、迁移                                                                                      |
| `stage`                | 恢复阶段 : init: 恢复尚未启动、index: 读取索引元数据并从源到目标复制字节、start: 启动引擎，打开索引使用、translog: 重放事务日志、finalize: 清理、done: 完成 |
| `primary`              | 值为true表示分片为主分片，false反之。                                                                                |
| `start_time`           | 开始恢复的时间戳                                                                                               |
| `stop_time`            | 完成恢复的时间戳                                                                                               |
| `total_time_in_millis` | 恢复分片的总时间(毫秒)                                                                                           |
| `source`               | 恢复源 : 如果恢复是来自快照的，则为存储库的描述、否则为源节点的描述                                                                    |
| `target`               | 目标节点                                                                                                   |
| `index`                | 物理索引恢复统计                                                                                               |
| `translog`             | 事务日志恢复统计                                                                                               |
| `start`                | 打开启动索引时间的统计信息                                                                                          |

## Indices Shard Stores 索引分片存储

提供索引的副本分片的存储信息。存储信息包括了:哪些节点存储分片副本，分片副本分配的ID，每个分片的唯一标识符以及打开分片索引时甚至更早期的引擎异常。

默认情况下，只有至少一个未分配的副本分片的列表存储信息。当集群健康状态为`yellow`时，将列出具有至少一个未分配副本分片的存储信息。当集群健康状态为`red`时，将列出具有未分配主分片的存储信息。

端点包括特定索引，多个索引或全部分片的存储信息：

```
curl -XGET 'http://localhost:9200/test/_shard_stores'
curl -XGET 'http://localhost:9200/test1,test2/_shard_stores'
curl -XGET 'http://localhost:9200/_shard_stores'
```

列出存储信息的分片范围可以通过`status`参数变更。默认为`yellow`和`red`。`yellow`列出至少一个未分配副本分片的信息，`red`列出有未分配的主分片的信息。使用`green`列出所有已分配的副本分片信息。

```
curl -XGET 'http://localhost:9200/_shard_stores?status=green'
```

响应：

分片存储信息按索引和分片ID分组。

```
{
    ...
   "0": { ①
        "stores": [ ②
            {
                "sPa3OgxLSYGvQ4oPs-Tajw": { ③
                    "name": "node_t0",
                    "transport_address": "local[1]",
                    "attributes": {
                        "mode": "local"
                    }
                },
                "allocation_id": "2iNySv_OQVePRX-yaRH_lQ", ④
                "legacy_version": 42, ⑤
                "allocation" : "primary" | "replica" | "unused", ⑥
                "store_exception": ... ⑦
            },
            ...
        ]
   },
    ...
}
```

① 这个键是存储信息对应的分片id

②所有分片副本的存储信息列表

③副本托管存储的节点信息，这个键是唯一节点id

④存储副本分片的id

⑤存储副本的版本（仅适用于在当前版本的**Elasticsearch**中尚未激活的旧版分区副本）

⑥存储副本的状态，无论用作主存储、副本存储还是不使用的副本。

⑦打开分片索引或更早引擎故障时遇到的异常信息。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/33-apis/341suo-yin-api/suo-5f15-3e-hui-590d-fen-pian-cun-chu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
