|
23 | 23 | import org.elasticsearch.indices.IndicesExpressionGrouper; |
24 | 24 | import org.elasticsearch.logging.LogManager; |
25 | 25 | import org.elasticsearch.logging.Logger; |
| 26 | +import org.elasticsearch.transport.RemoteClusterAware; |
26 | 27 | import org.elasticsearch.xpack.esql.VerificationException; |
27 | 28 | import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo; |
28 | 29 | import org.elasticsearch.xpack.esql.action.EsqlQueryRequest; |
|
81 | 82 |
|
82 | 83 | import java.util.ArrayList; |
83 | 84 | import java.util.HashMap; |
| 85 | +import java.util.HashSet; |
84 | 86 | import java.util.Iterator; |
85 | 87 | import java.util.List; |
86 | 88 | import java.util.Map; |
@@ -361,10 +363,8 @@ public void analyzedPlan( |
361 | 363 | EsqlCCSUtils.checkForCcsLicense(executionInfo, indices, indicesExpressionGrouper, configuredClusters, verifier.licenseState()); |
362 | 364 | initializeClusterData(indices, executionInfo); |
363 | 365 |
|
364 | | - final Set<String> targetClusters = executionInfo.getClusters().keySet(); |
365 | | - |
366 | 366 | var listener = SubscribableListener.<EnrichResolution>newForked( |
367 | | - l -> enrichPolicyResolver.resolvePolicies(targetClusters, unresolvedPolicies, executionInfo, l) |
| 367 | + l -> enrichPolicyResolver.resolvePolicies(getEnrichTargets(executionInfo), unresolvedPolicies, executionInfo, l) |
368 | 368 | ) |
369 | 369 | .<PreAnalysisResult>andThen((l, enrichResolution) -> resolveFieldNames(parsed, enrichResolution, l)) |
370 | 370 | .<PreAnalysisResult>andThen((l, preAnalysisResult) -> resolveInferences(preAnalysis.inferencePlans, preAnalysisResult, l)); |
@@ -413,6 +413,15 @@ public void analyzedPlan( |
413 | 413 | }).addListener(logicalPlanListener); |
414 | 414 | } |
415 | 415 |
|
| 416 | + private static Set<String> getEnrichTargets(EsqlExecutionInfo executionInfo) { |
| 417 | + Set<String> targetClusters = executionInfo.getClusters().keySet(); |
| 418 | + if (targetClusters.isEmpty()) { |
| 419 | + // Always include local cluster for enrich resolution |
| 420 | + return Set.of(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY); |
| 421 | + } |
| 422 | + return targetClusters; |
| 423 | + } |
| 424 | + |
416 | 425 | private void preAnalyzeLookupIndex(IndexPattern table, PreAnalysisResult result, ActionListener<PreAnalysisResult> listener) { |
417 | 426 | Set<String> fieldNames = result.wildcardJoinIndices().contains(table.indexPattern()) ? IndexResolver.ALL_FIELDS : result.fieldNames; |
418 | 427 | // call the EsqlResolveFieldsAction (field-caps) to resolve indices and get field types |
|
0 commit comments