--- title: "路由异常 (routing_exception) 错误排查与解决" date: 2026-02-25 lastmod: 2026-02-25 description: "routing_exception 表示与分片路由相关的通用异常,通常由分片未分配、路由计算错误或分配规则限制引起。" tags: ["分片路由", "分片分配"] summary: "为什么这个错误发生 # routing_exception 是与分片路由相关的通用异常,表示分片分配或路由操作失败。 这个错误可能由以下原因引起: 分片未分配:目标分片未分配到任何节点 路由计算错误:文档路由值计算错误 分配规则限制:分配规则阻止分片分配 节点离线:目标节点离线 索引状态异常:索引处于关闭或不可用状态 如何修复这个错误 # 1. 检查分片状态 # # 查看未分配的分片 GET /_cat/shards?v | grep UNASSIGNED # 解释分配失败原因 GET /_cluster/allocation/explain 2. 启用分片分配 # # 确保分片分配已启用 PUT /_cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } } 3. 重试分配 # # 重试失败的分配 POST /_cluster/reroute?retry_failed=true 4. 检查索引状态 # # 确保索引是打开状态 GET /<index>/_explain # 打开已关闭的索引 POST /<index>/_open 5. 检查磁盘空间 # # 查看磁盘使用情况 GET /_cat/allocation?" --- ## 为什么这个错误发生 `routing_exception` 是与分片路由相关的通用异常,表示分片分配或路由操作失败。 这个错误可能由以下原因引起: 1. **分片未分配**:目标分片未分配到任何节点 2. **路由计算错误**:文档路由值计算错误 3. **分配规则限制**:分配规则阻止分片分配 4. **节点离线**:目标节点离线 5. **索引状态异常**:索引处于关闭或不可用状态 ## 如何修复这个错误 ### 1. 检查分片状态 ```bash # 查看未分配的分片 GET /_cat/shards?v | grep UNASSIGNED # 解释分配失败原因 GET /_cluster/allocation/explain ``` ### 2. 启用分片分配 ```bash # 确保分片分配已启用 PUT /_cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } } ``` ### 3. 重试分配 ```bash # 重试失败的分配 POST /_cluster/reroute?retry_failed=true ``` ### 4. 检查索引状态 ```bash # 确保索引是打开状态 GET //_explain # 打开已关闭的索引 POST //_open ``` ### 5. 检查磁盘空间 ```bash # 查看磁盘使用情况 GET /_cat/allocation?v ``` ### 6. 调整分配规则 ```bash # 移除分配排除规则 PUT /_cluster/settings { "persistent": { "cluster.routing.allocation.exclude._name": null } } ``` ### 预防措施 - 确保充足的磁盘空间 - 配置合理的副本数 - 监控分片分配状态 - 避免手动排除节点