--- title: "仅当分片状态为指定状态时才允许操作 – 如何解决此 Elasticsearch 异常" date: 2026-01-23 lastmod: 2026-01-23 description: "当 Elasticsearch 中的分片未处于正确状态时尝试执行操作会导致此错误。Elasticsearch 操作只能在分片状态为已启动或已重定位时执行。" tags: ["分片状态", "异常处理", "索引分片"] summary: " 版本: 6.8-7.15 简而言之,当在 Elasticsearch 中对未处于正确状态的分片尝试执行操作时,会发生此错误。Elasticsearch 操作只能在分片状态为已启动(started)或已重定位(relocated)时执行。如果分片处于不正确的状态,例如正在初始化(initializing)、正在关闭(closing)或已关闭(closed),则无法执行操作。要解决此问题,您可以等待分片达到正确状态,或者手动更改分片状态。但是,手动更改分片状态应谨慎操作,因为这可能导致数据丢失或损坏。 日志上下文 # 日志 “operations only allowed when shard state is one of” 的类名是 IndexShard.java。 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: } public void readAllowed() throws IllegalIndexShardStateException { IndexShardState state = this.state; // one time volatile read if (readAllowedStates.contains(state) == false) { throw new IllegalIndexShardStateException(shardId; state; "operations only allowed when shard state is one of " + readAllowedStates.toString()); } } /** returns true if the {@link IndexShardState} allows reading */ " --- > **版本:** 6.8-7.15 简而言之,当在 Elasticsearch 中对未处于正确状态的分片尝试执行操作时,会发生此错误。Elasticsearch 操作只能在分片状态为已启动(started)或已重定位(relocated)时执行。如果分片处于不正确的状态,例如正在初始化(initializing)、正在关闭(closing)或已关闭(closed),则无法执行操作。要解决此问题,您可以等待分片达到正确状态,或者手动更改分片状态。但是,手动更改分片状态应谨慎操作,因为这可能导致数据丢失或损坏。 日志上下文 ----------- 日志 "operations only allowed when shard state is one of" 的类名是 [IndexShard.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入上下文的人使用: ```java } public void readAllowed() throws IllegalIndexShardStateException { IndexShardState state = this.state; // one time volatile read if (readAllowedStates.contains(state) == false) { throw new IllegalIndexShardStateException(shardId; state; "operations only allowed when shard state is one of " + readAllowedStates.toString()); } } /** returns true if the {@link IndexShardState} allows reading */ ```