|
30 | 30 | import org.elasticsearch.action.admin.cluster.shards.TransportClusterSearchShardsAction; |
31 | 31 | import org.elasticsearch.action.admin.cluster.stats.CCSUsage; |
32 | 32 | import org.elasticsearch.action.admin.cluster.stats.CCSUsageTelemetry; |
| 33 | +import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction; |
33 | 34 | import org.elasticsearch.action.support.ActionFilters; |
34 | 35 | import org.elasticsearch.action.support.HandledTransportAction; |
35 | 36 | import org.elasticsearch.action.support.IndicesOptions; |
@@ -512,43 +513,58 @@ public void onFailure(Exception e) { |
512 | 513 | } else { |
513 | 514 | final TaskId parentTaskId = task.taskInfo(clusterService.localNode().getId(), false).taskId(); |
514 | 515 | if (shouldMinimizeRoundtrips(rewritten)) { |
515 | | - final AggregationReduceContext.Builder aggregationReduceContextBuilder = rewritten.source() != null |
516 | | - && rewritten.source().aggregations() != null |
517 | | - ? searchService.aggReduceContextBuilder(task::isCancelled, rewritten.source().aggregations()) |
518 | | - : null; |
519 | | - SearchResponse.Clusters clusters = new SearchResponse.Clusters( |
520 | | - resolvedIndices.getLocalIndices(), |
521 | | - resolvedIndices.getRemoteClusterIndices(), |
522 | | - true, |
523 | | - (clusterAlias) -> remoteClusterService.shouldSkipOnFailure(clusterAlias, rewritten.allowPartialSearchResults()) |
524 | | - ); |
525 | | - if (resolvedIndices.getLocalIndices() == null) { |
526 | | - // Notify the progress listener that a CCS with minimize_roundtrips is happening remote-only (no local shards) |
527 | | - task.getProgressListener() |
528 | | - .notifyListShards(Collections.emptyList(), Collections.emptyList(), clusters, false, timeProvider); |
529 | | - } |
530 | | - ccsRemoteReduce( |
531 | | - task, |
532 | | - parentTaskId, |
533 | | - rewritten, |
| 516 | + collectResolvedIndices( |
| 517 | + resolvesCrossProject, |
| 518 | + original, |
534 | 519 | resolvedIndices, |
535 | | - clusters, |
536 | | - timeProvider, |
537 | | - aggregationReduceContextBuilder, |
538 | | - remoteClusterService, |
539 | | - threadPool, |
540 | | - searchResponseActionListener, |
541 | | - (r, l) -> executeLocalSearch( |
542 | | - task, |
543 | | - timeProvider, |
544 | | - r, |
545 | | - resolvedIndices, |
546 | | - projectState, |
547 | | - clusters, |
548 | | - searchPhaseProvider.apply(l) |
549 | | - ), |
550 | | - transportService, |
551 | | - forceConnectTimeoutSecs |
| 520 | + resolutionIdxOpts, |
| 521 | + projectState.metadata(), |
| 522 | + indexNameExpressionResolver, |
| 523 | + timeProvider.absoluteStartMillis(), |
| 524 | + searchResponseActionListener.delegateFailureAndWrap((searchListener, replacedIndices) -> { |
| 525 | + final AggregationReduceContext.Builder aggregationReduceContextBuilder = rewritten.source() != null |
| 526 | + && rewritten.source().aggregations() != null |
| 527 | + ? searchService.aggReduceContextBuilder(task::isCancelled, rewritten.source().aggregations()) |
| 528 | + : null; |
| 529 | + SearchResponse.Clusters clusters = new SearchResponse.Clusters( |
| 530 | + replacedIndices.getLocalIndices(), |
| 531 | + replacedIndices.getRemoteClusterIndices(), |
| 532 | + true, |
| 533 | + (clusterAlias) -> remoteClusterService.shouldSkipOnFailure( |
| 534 | + clusterAlias, |
| 535 | + rewritten.allowPartialSearchResults() |
| 536 | + ) |
| 537 | + ); |
| 538 | + if (replacedIndices.getLocalIndices() == null) { |
| 539 | + // Notify the progress listener that a CCS with minimize_roundtrips is happening remote-only (no local |
| 540 | + // shards) |
| 541 | + task.getProgressListener() |
| 542 | + .notifyListShards(Collections.emptyList(), Collections.emptyList(), clusters, false, timeProvider); |
| 543 | + } |
| 544 | + ccsRemoteReduce( |
| 545 | + task, |
| 546 | + parentTaskId, |
| 547 | + rewritten, |
| 548 | + replacedIndices, |
| 549 | + clusters, |
| 550 | + timeProvider, |
| 551 | + aggregationReduceContextBuilder, |
| 552 | + remoteClusterService, |
| 553 | + threadPool, |
| 554 | + searchListener, |
| 555 | + (r, l) -> executeLocalSearch( |
| 556 | + task, |
| 557 | + timeProvider, |
| 558 | + r, |
| 559 | + replacedIndices, |
| 560 | + projectState, |
| 561 | + clusters, |
| 562 | + searchPhaseProvider.apply(l) |
| 563 | + ), |
| 564 | + transportService, |
| 565 | + forceConnectTimeoutSecs |
| 566 | + ); |
| 567 | + }) |
552 | 568 | ); |
553 | 569 | } else { |
554 | 570 | final SearchContextId searchContext = resolvedIndices.getSearchContextId(); |
@@ -1047,6 +1063,44 @@ static SearchResponse.Clusters reconcileProjects( |
1047 | 1063 | return new SearchResponse.Clusters(reconciledMap, false); |
1048 | 1064 | } |
1049 | 1065 |
|
| 1066 | + void collectResolvedIndices( |
| 1067 | + boolean resolvesCrossProject, |
| 1068 | + SearchRequest original, |
| 1069 | + ResolvedIndices originalResolvedIndices, |
| 1070 | + IndicesOptions resolutionIdxOpts, |
| 1071 | + ProjectMetadata projectMetadata, |
| 1072 | + IndexNameExpressionResolver indexNameExpressionResolver, |
| 1073 | + long startTimeInMillis, |
| 1074 | + ActionListener<ResolvedIndices> listener |
| 1075 | + ) { |
| 1076 | + if (resolvesCrossProject) { |
| 1077 | + final ResolveIndexAction.Request resolveIndexRequest = new ResolveIndexAction.Request( |
| 1078 | + original.indices(), |
| 1079 | + original.indicesOptions(), |
| 1080 | + null, |
| 1081 | + original.getProjectRouting() |
| 1082 | + ); |
| 1083 | + |
| 1084 | + client.execute( |
| 1085 | + ResolveIndexAction.INSTANCE, |
| 1086 | + resolveIndexRequest, |
| 1087 | + listener.delegateFailureAndWrap( |
| 1088 | + (l, r) -> l.onResponse( |
| 1089 | + ResolvedIndices.resolveFromResponse( |
| 1090 | + r, |
| 1091 | + resolutionIdxOpts, |
| 1092 | + projectMetadata, |
| 1093 | + indexNameExpressionResolver, |
| 1094 | + startTimeInMillis |
| 1095 | + ) |
| 1096 | + ) |
| 1097 | + ) |
| 1098 | + ); |
| 1099 | + } else { |
| 1100 | + listener.onResponse(originalResolvedIndices); |
| 1101 | + } |
| 1102 | + } |
| 1103 | + |
1050 | 1104 | /** |
1051 | 1105 | * Collect remote search shards that we need to search for potential matches. |
1052 | 1106 | * Used for ccs_minimize_roundtrips=false |
|
0 commit comments