diff --git a/server/src/main/java/org/elasticsearch/search/SearchService.java b/server/src/main/java/org/elasticsearch/search/SearchService.java index 3ea467fa67b41..2358287bf5f31 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchService.java +++ b/server/src/main/java/org/elasticsearch/search/SearchService.java @@ -30,6 +30,7 @@ import org.elasticsearch.action.support.TransportActions; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; +import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.CheckedSupplier; @@ -511,7 +512,7 @@ public void beforeIndexShardCreated(ShardRouting routing, Settings indexSettings // to stop searches to restore full availability as fast as possible. A known scenario here is that we lost connection to master // or master(s) were restarted. assert routing.initializing(); - if (routing.isRelocationTarget() == false) { + if (routing.isRelocationTarget() == false && routing.recoverySource() != RecoverySource.EmptyStoreRecoverySource.INSTANCE) { freeAllContextsForShard(routing.shardId()); } }