--- title: "操作仅在分片状态为特定值时被允许 - 如何解决此 Elasticsearch 异常" date: 2026-03-22 lastmod: 2026-03-22 description: "当在状态不正确的分片上尝试执行操作时,会出现此错误。Elasticsearch 操作只能对处于特定状态的分片(如 STARTED 或 RELOCATING)执行。如果分片处于 INITIALIZING 或 CLOSED 等不适当的状态,则无法执行操作。" tags: ["分片状态", "异常处理", "索引分片"] summary: " 版本: 6.8-7.15 简而言之,当在状态不正确的分片上尝试执行操作时,会发生此错误。Elasticsearch 操作只能对处于特定状态(如 STARTED 或 RELOCATING)的分片执行。如果分片处于 INITIALIZING 或 CLOSED 等不适当的状态,则无法执行操作。要解决此问题,您可以等待分片转换到适当的状态,或者手动更改分片状态。但是,手动干预应谨慎进行,因为它可能导致数据丢失或损坏。 日志上下文 # 日志 “operation only allowed when shard state is one of” 的类名是 IndexShard.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: assert origin == Engine.Operation.Origin.LOCAL_RESET; assert getActiveOperationsCount() == OPERATIONS_BLOCKED : "locally resetting without blocking operations; active operations are [" + getActiveOperations() + "]"; } if (writeAllowedStates.contains(state) == false) { throw new IllegalIndexShardStateException(shardId; state; "operation only allowed when shard state is one of " + writeAllowedStates + "; origin [" + origin + "]"); } } } " --- > **版本:** 6.8-7.15 简而言之,当在状态不正确的分片上尝试执行操作时,会发生此错误。Elasticsearch 操作只能对处于特定状态(如 STARTED 或 RELOCATING)的分片执行。如果分片处于 INITIALIZING 或 CLOSED 等不适当的状态,则无法执行操作。要解决此问题,您可以等待分片转换到适当的状态,或者手动更改分片状态。但是,手动干预应谨慎进行,因为它可能导致数据丢失或损坏。 日志上下文 ----------- 日志 "operation only allowed when shard state is one of" 的类名是 [IndexShard.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考: ```java assert origin == Engine.Operation.Origin.LOCAL_RESET; assert getActiveOperationsCount() == OPERATIONS_BLOCKED : "locally resetting without blocking operations; active operations are [" + getActiveOperations() + "]"; } if (writeAllowedStates.contains(state) == false) { throw new IllegalIndexShardStateException(shardId; state; "operation only allowed when shard state is one of " + writeAllowedStates + "; origin [" + origin + "]"); } } } ```