--- title: "分片标记为已重定位,无法安全移动到指定状态 - 如何解决此 Elasticsearch 异常" date: 2026-03-18 lastmod: 2026-03-18 description: "当 Elasticsearch 尝试将分片移动到节点时,但该分片已被标记为已重定位,会引发此异常。这通常由于网络问题或节点故障导致。" tags: ["分片管理", "节点故障", "集群重路由"] summary: "版本: 6.8-7.15 简而言之,当 Elasticsearch 尝试将分片移动到节点时,但该分片已被标记为已重定位,就会发生此错误。这通常由于网络问题或节点故障导致。要解决此问题,可以尝试重启 Elasticsearch 节点,或使用集群重路由 API 手动重新路由分片。如果问题持续存在,建议检查网络配置或节点的健康状况。 日志上下文 # 日志"Shard is marked as relocated; cannot safely move to state"的类名为 IndexShard.java。 我们从 Elasticsearch 源代码中提取了以下内容,供寻求深入上下文的用户参考: } else if (currentRouting.primary() && currentRouting.relocating() && replicationTracker.isRelocated() && (newRouting.relocating() == false || newRouting.equalsIgnoringMetadata(currentRouting) == false)) { // if the shard is not in primary mode anymore (after primary relocation) we have to fail when any changes in shard // routing occur (e." --- > **版本:** 6.8-7.15 简而言之,当 Elasticsearch 尝试将分片移动到节点时,但该分片已被标记为已重定位,就会发生此错误。这通常由于网络问题或节点故障导致。要解决此问题,可以尝试重启 Elasticsearch 节点,或使用集群重路由 API 手动重新路由分片。如果问题持续存在,建议检查网络配置或节点的健康状况。 日志上下文 ----------- 日志"Shard is marked as relocated; cannot safely move to state"的类名为 [IndexShard.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供寻求深入上下文的用户参考: ```java } else if (currentRouting.primary() && currentRouting.relocating() && replicationTracker.isRelocated() && (newRouting.relocating() == false || newRouting.equalsIgnoringMetadata(currentRouting) == false)) { // if the shard is not in primary mode anymore (after primary relocation) we have to fail when any changes in shard // routing occur (e.g. due to recovery failure / cancellation). The reason is that at the moment we cannot safely // reactivate primary mode without risking two active primaries. throw new IndexShardRelocatedException(shardId(); "Shard is marked as relocated; cannot safely move to state " + newRouting.state()); } assert newRouting.active() == false || state == IndexShardState.STARTED || state == IndexShardState.CLOSED : "routing is active; but local shard state isn't. routing: " + newRouting + "; local state: " + state; persistMetadata(path; indexSettings; newRouting; currentRouting; logger); ```