分片存储
_shard_stores
API 提供了有关一个或多个索引的分片副本信息。此 API 通过指示分片未分配的原因并提供其当前状态来帮助诊断未分配分片的问题。
端点
GET /_shard_stores
GET /{index}/_shard_stores
路径参数
下表列出了可用的路径参数。所有路径参数均为可选。
参数 | 数据类型 | 描述 |
---|---|---|
index | 列表或字符串 | 用于限制请求的数据流、索引和别名列表。 |
查询参数
下表列出了可用的查询参数。所有查询参数都是可选的。
参数 | 数据类型 | 描述 | 默认值 |
allow_no_indices | 布尔型 | 如果为 false ,则当任何通配符表达式、索引别名或 _all 值仅针对缺失或已关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。 | false |
expand_wildcards | 列表或字符串 | 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数将确定通配符表达式是否匹配隐藏数据流。 有效值为 - all :匹配任何索引,包括隐藏索引。- closed :匹配已关闭的非隐藏索引。- hidden :匹配隐藏索引。必须与 open、closed 或两者结合使用。- none :不接受通配符表达式。- open :匹配已打开的非隐藏索引。 | 打开 |
ignore_unavailable | 布尔型 | 如果为 true ,则响应中不包含缺失或已关闭的索引。 | false |
status | 列表或字符串 | 用于限制请求的分片健康状态列表。 有效值为 - all :返回所有分片,无论健康状态如何。- green :主分片和所有副本分片都已分配。- red :主分片未分配。- yellow :一个或多个副本分片未分配。 | yellow,red |
示例
在单节点集群上创建具有多个主分片的索引
PUT /logs-shardstore
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"timestamp": { "type": "date" },
"message": { "type": "text" }
}
}
}
索引文档
POST /logs-shardstore/_doc
{
"timestamp": "2025-06-20T12:00:00Z",
"message": "Log message 1"
}
获取 logs-shardstore
索引的分片存储状态
GET /logs-shardstore/_shard_stores?status=all
示例响应
响应列出了分配给每个分片的存储。如果分片没有分配的存储,则标记为 unassigned
{
"indices": {
"logs-shardstore": {
"shards": {
"0": {
"stores": [
{
"UFyVYVMCSDOObiRwPxSW5w": {
"name": "opensearch-node1",
"ephemeral_id": "vkSB_-M7QVyFXvgda6oRZg",
"transport_address": "172.19.0.2:9300",
"attributes": {
"shard_indexing_pressure_enabled": "true"
}
},
"allocation_id": "PEM5YjEWSz-jJEj-Not6Aw",
"allocation": "primary"
}
]
},
"1": {
"stores": []
}
}
}
}
}
响应正文字段
下表列出了所有响应正文字段。
字段 | 数据类型 | 描述 |
索引 | 对象 | 包含每个索引的分片存储信息。 |
indices.<index>.shards | 对象 | 包含索引中每个分片的存储数据。 |
shards.<shard_id>.stores | 数组 | 分片的存储条目列表。 |
stores[n].<node_id> | 对象 | 节点元数据,包括名称、传输地址和属性。 |
stores[n].allocation | 字符串 | 此节点上的分片角色(primary 或 replica )。 |
stores[n].allocation_id | 字符串 | 此分片副本的唯一分配 ID。 |
stores[n].store_exception | 对象(可选) | 存储读取分片存储时遇到的异常。 |
stores[n].store_exception.type | 字符串 | 异常类型。 |
stores[n].store_exception.reason | 字符串 | 异常原因消息。 |