解决 Elasticsearch 报错 primary shard is not active 超时 1m 故障
分析 Elasticsearch 写入文档时因主分片正在恢复未激活超时报 not active 根因,提供分片分配解释与重平衡方案。
问题现象
写入 Elasticsearch 时报错返回:
{
"error": {
"root_cause": [
{
"type": "unavailable_shards_exception",
"reason": "[my-index][0] primary shard is not active Timeout: [1m],
request: [BulkShardRequest to [my-index] ...]"
}
]
},
"status": 503
}
触发根因
目标主分片当前处于 INITIALIZING 或未分配状态,正在从磁盘重放恢复,等待超过 1 分钟后请求超时。
解决步骤与操作命令
步骤一:定位未分配分片原因并强制恢复
curl -s "http://localhost:9200/_cluster/allocation/explain?pretty"
触发重试:
curl -X POST "http://localhost:9200/_cluster/reroute?retry_failed=true"
等待分片激活后,写入恢复毫秒级响应。


