21
21
import org .elasticsearch .cluster .ClusterState ;
22
22
import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
23
23
import org .elasticsearch .cluster .node .DiscoveryNode ;
24
+ import org .elasticsearch .cluster .routing .OperationRouting ;
24
25
import org .elasticsearch .cluster .routing .PlainShardIterator ;
25
26
import org .elasticsearch .cluster .routing .ShardIterator ;
26
- import org .elasticsearch .cluster .routing .ShardRouting ;
27
27
import org .elasticsearch .cluster .service .ClusterService ;
28
28
import org .elasticsearch .common .inject .Inject ;
29
29
import org .elasticsearch .common .io .stream .Writeable ;
@@ -101,7 +101,10 @@ protected ShardIterator shards(ClusterState state, InternalRequest request) {
101
101
if (iterator == null ) {
102
102
return null ;
103
103
}
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
+ );
105
108
}
106
109
107
110
@ Override
@@ -110,11 +113,14 @@ protected void asyncShardOperation(MultiGetShardRequest request, ShardId shardId
110
113
IndexService indexService = indicesService .indexServiceSafe (shardId .getIndex ());
111
114
IndexShard indexShard = indexService .getShard (shardId .id ());
112
115
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" ;
113
118
handleMultiGetOnUnpromotableShard (request , indexShard , listener );
114
119
return ;
115
120
}
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" ;
118
124
if (request .realtime ()) { // we are not tied to a refresh cycle here anyway
119
125
asyncShardMultiGet (request , shardId , listener );
120
126
} else {
0 commit comments