--- title: "分片迁移期间无法创建快照 - 如何解决此Elasticsearch异常" date: 2026-03-25 lastmod: 2026-03-25 description: "当Elasticsearch在分片迁移过程中尝试创建索引快照时,会出现此错误。这是不被允许的操作,因为可能导致快照数据不一致。本文提供解决方案和详细的技术背景。" tags: ["Elasticsearch", "快照操作", "分片迁移", "并发冲突", "集群管理"] summary: "版本: 6.8-8.9 简要来说,当Elasticsearch在分片迁移过程正在进行时尝试创建索引快照,就会出现此错误。这是不被允许的操作,因为它可能导致快照中的数据不一致。要解决此问题,您可以在启动快照之前等待分片迁移完成,或者在快照过程中临时停止分片迁移。此外,确保在创建快照时集群稳定且未处于高负载状态,以防止发生分片迁移。 日志上下文 # 日志 “cannot snapshot while relocating” 的类名是 SnapshotShardsService.java。 我们从Elasticsearch源代码中提取了以下内容,供那些需要深入了解上下文的用户参考: if (indexShard.routingEntry().primary() == false) { throw new IndexShardSnapshotFailedException(shardId; "snapshot should be performed only on primary"); } if (indexShard.routingEntry().relocating()) { // do not snapshot when in the process of relocation of primaries so we won't get conflicts throw new IndexShardSnapshotFailedException(shardId; "cannot snapshot while relocating"); } final IndexShardState indexShardState = indexShard.state(); if (indexShardState == IndexShardState.CREATED || indexShardState == IndexShardState." --- > **版本:** 6.8-8.9 简要来说,当Elasticsearch在分片迁移过程正在进行时尝试创建索引快照,就会出现此错误。这是不被允许的操作,因为它可能导致快照中的数据不一致。要解决此问题,您可以在启动快照之前等待分片迁移完成,或者在快照过程中临时停止分片迁移。此外,确保在创建快照时集群稳定且未处于高负载状态,以防止发生分片迁移。 日志上下文 ----------- 日志 "cannot snapshot while relocating" 的类名是 [SnapshotShardsService.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从Elasticsearch源代码中提取了以下内容,供那些需要深入了解上下文的用户参考: ```java if (indexShard.routingEntry().primary() == false) { throw new IndexShardSnapshotFailedException(shardId; "snapshot should be performed only on primary"); } if (indexShard.routingEntry().relocating()) { // do not snapshot when in the process of relocation of primaries so we won't get conflicts throw new IndexShardSnapshotFailedException(shardId; "cannot snapshot while relocating"); } final IndexShardState indexShardState = indexShard.state(); if (indexShardState == IndexShardState.CREATED || indexShardState == IndexShardState.RECOVERING) { // shard has just been created; or still recovering ```