@@ -325,33 +325,29 @@ public static void initCrossClusterState(
325325 return ;
326326 }
327327 try {
328- // TODO it is not safe to concat multiple index patterns in case any of them contains exclusion.
329- // This is going to be resolved in #136804
330- String [] indexExpressions = indexPatterns .stream ()
331- .map (indexPattern -> Strings .splitStringByCommaToArray (indexPattern .indexPattern ()))
332- .reduce ((a , b ) -> {
333- String [] combined = new String [a .length + b .length ];
334- System .arraycopy (a , 0 , combined , 0 , a .length );
335- System .arraycopy (b , 0 , combined , a .length , b .length );
336- return combined ;
337- })
338- .get ();
339- var groupedIndices = indicesGrouper .groupIndices (IndicesOptions .DEFAULT , indexExpressions , false );
328+ for (IndexPattern indexPattern : indexPatterns ) {
329+ var groupedIndices = indicesGrouper .groupIndices (
330+ IndicesOptions .DEFAULT ,
331+ Strings .splitStringByCommaToArray (indexPattern .indexPattern ()),
332+ false
333+ );
340334
341- executionInfo .clusterInfoInitializing (true );
342- // initialize the cluster entries in EsqlExecutionInfo before throwing the invalid license error
343- // so that the CCS telemetry handler can recognize that this error is CCS-related
344- try {
345- for (var entry : groupedIndices .entrySet ()) {
346- final String clusterAlias = entry .getKey ();
347- final String indexExpr = Strings .arrayToCommaDelimitedString (entry .getValue ().indices ());
348- executionInfo .swapCluster (clusterAlias , (k , v ) -> {
349- assert v == null : "No cluster for " + clusterAlias + " should have been added to ExecutionInfo yet" ;
350- return new EsqlExecutionInfo .Cluster (clusterAlias , indexExpr , executionInfo .shouldSkipOnFailure (clusterAlias ));
335+ executionInfo .clusterInfoInitializing (true );
336+ // initialize the cluster entries in EsqlExecutionInfo before throwing the invalid license error
337+ // so that the CCS telemetry handler can recognize that this error is CCS-related
338+ try {
339+ groupedIndices .forEach ((clusterAlias , indices ) -> {
340+ executionInfo .swapCluster (clusterAlias , (k , v ) -> {
341+ var indexExpr = Strings .arrayToCommaDelimitedString (indices .indices ());
342+ if (v != null ) {
343+ indexExpr = v .getIndexExpression () + "," + indexExpr ;
344+ }
345+ return new EsqlExecutionInfo .Cluster (clusterAlias , indexExpr , executionInfo .shouldSkipOnFailure (clusterAlias ));
346+ });
351347 });
348+ } finally {
349+ executionInfo .clusterInfoInitializing (false );
352350 }
353- } finally {
354- executionInfo .clusterInfoInitializing (false );
355351 }
356352
357353 if (executionInfo .isCrossClusterSearch () && EsqlLicenseChecker .isCcsAllowed (licenseState ) == false ) {
0 commit comments