2121import org .elasticsearch .cluster .ClusterState ;
2222import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
2323import org .elasticsearch .cluster .node .DiscoveryNode ;
24+ import org .elasticsearch .cluster .routing .OperationRouting ;
2425import org .elasticsearch .cluster .routing .PlainShardIterator ;
2526import org .elasticsearch .cluster .routing .ShardIterator ;
26- import org .elasticsearch .cluster .routing .ShardRouting ;
2727import org .elasticsearch .cluster .service .ClusterService ;
2828import org .elasticsearch .common .inject .Inject ;
2929import org .elasticsearch .common .io .stream .Writeable ;
@@ -101,7 +101,10 @@ protected ShardIterator shards(ClusterState state, InternalRequest request) {
101101 if (iterator == null ) {
102102 return null ;
103103 }
104- return new PlainShardIterator (iterator .shardId (), iterator .getShardRoutings ().stream ().filter (ShardRouting ::isSearchable ).toList ());
104+ return new PlainShardIterator (
105+ iterator .shardId (),
106+ iterator .getShardRoutings ().stream ().filter (shardRouting -> OperationRouting .canSearchShard (shardRouting , state )).toList ()
107+ );
105108 }
106109
107110 @ Override
@@ -110,11 +113,14 @@ protected void asyncShardOperation(MultiGetShardRequest request, ShardId shardId
110113 IndexService indexService = indicesService .indexServiceSafe (shardId .getIndex ());
111114 IndexShard indexShard = indexService .getShard (shardId .id ());
112115 if (indexShard .routingEntry ().isPromotableToPrimary () == false ) {
116+ assert indexShard .indexSettings ().isFastRefresh () == false
117+ : "a search shard should not receive a TransportShardMultiGetAction for an index with fast refresh" ;
113118 handleMultiGetOnUnpromotableShard (request , indexShard , listener );
114119 return ;
115120 }
116- assert DiscoveryNode .isStateless (clusterService .getSettings ()) == false
117- : "A TransportShardMultiGetAction should always be handled by a search shard in Stateless" ;
121+ assert DiscoveryNode .isStateless (clusterService .getSettings ()) == false || indexShard .indexSettings ().isFastRefresh ()
122+ : "in Stateless a promotable to primary shard can receive a TransportShardMultiGetAction only if an index has "
123+ + "the fast refresh setting" ;
118124 if (request .realtime ()) { // we are not tied to a refresh cycle here anyway
119125 asyncShardMultiGet (request , shardId , listener );
120126 } else {
0 commit comments