3333import org .elasticsearch .cluster .routing .GroupShardsIterator ;
3434import org .elasticsearch .cluster .routing .ShardIterator ;
3535import org .elasticsearch .cluster .service .ClusterService ;
36- import org .elasticsearch .common .Strings ;
3736import org .elasticsearch .common .inject .Inject ;
3837import org .elasticsearch .common .settings .Setting ;
3938import org .elasticsearch .common .settings .Setting .Property ;
@@ -184,7 +183,7 @@ protected void doExecute(Task task, SearchRequest searchRequest, ActionListener<
184183 searchRequest .indices (), idx -> indexNameExpressionResolver .hasIndexOrAlias (idx , clusterState ));
185184 OriginalIndices localIndices = remoteClusterIndices .remove (RemoteClusterAware .LOCAL_CLUSTER_GROUP_KEY );
186185 if (remoteClusterIndices .isEmpty ()) {
187- executeSearch ((SearchTask )task , timeProvider , searchRequest , localIndices , Collections .emptyList (),
186+ executeSearch ((SearchTask )task , timeProvider , searchRequest , localIndices , remoteClusterIndices , Collections .emptyList (),
188187 (clusterName , nodeId ) -> null , clusterState , Collections .emptyMap (), listener );
189188 } else {
190189 remoteClusterService .collectSearchShards (searchRequest .indicesOptions (), searchRequest .preference (), searchRequest .routing (),
@@ -193,7 +192,7 @@ protected void doExecute(Task task, SearchRequest searchRequest, ActionListener<
193192 Map <String , AliasFilter > remoteAliasFilters = new HashMap <>();
194193 BiFunction <String , String , DiscoveryNode > clusterNodeLookup = processRemoteShards (searchShardsResponses ,
195194 remoteClusterIndices , remoteShardIterators , remoteAliasFilters );
196- executeSearch ((SearchTask )task , timeProvider , searchRequest , localIndices , remoteShardIterators ,
195+ executeSearch ((SearchTask ) task , timeProvider , searchRequest , localIndices , remoteClusterIndices , remoteShardIterators ,
197196 clusterNodeLookup , clusterState , remoteAliasFilters , listener );
198197 }, listener ::onFailure ));
199198 }
@@ -249,16 +248,16 @@ static BiFunction<String, String, DiscoveryNode> processRemoteShards(Map<String,
249248 }
250249
251250 private void executeSearch (SearchTask task , SearchTimeProvider timeProvider , SearchRequest searchRequest , OriginalIndices localIndices ,
252- List < SearchShardIterator > remoteShardIterators , BiFunction < String , String , DiscoveryNode > remoteConnections ,
253- ClusterState clusterState , Map < String , AliasFilter > remoteAliasMap ,
254- ActionListener <SearchResponse > listener ) {
251+ Map < String , OriginalIndices > remoteClusterIndices , List < SearchShardIterator > remoteShardIterators ,
252+ BiFunction < String , String , DiscoveryNode > remoteConnections , ClusterState clusterState ,
253+ Map < String , AliasFilter > remoteAliasMap , ActionListener <SearchResponse > listener ) {
255254
256255 clusterState .blocks ().globalBlockedRaiseException (ClusterBlockLevel .READ );
257256 // TODO: I think startTime() should become part of ActionRequest and that should be used both for index name
258257 // date math expressions and $now in scripts. This way all apis will deal with now in the same way instead
259258 // of just for the _search api
260259 final Index [] indices ;
261- if (localIndices .indices ().length == 0 && remoteShardIterators . size () > 0 ) {
260+ if (localIndices .indices ().length == 0 && remoteClusterIndices . isEmpty () == false ) {
262261 indices = Index .EMPTY_ARRAY ; // don't search on _all if only remote indices were specified
263262 } else {
264263 indices = indexNameExpressionResolver .concreteIndices (clusterState , searchRequest .indicesOptions (),
0 commit comments