Skip to content

Commit b4d23a9

Browse files
authored
Wire project routing to FC (#138714)
1 parent c2a3ab6 commit b4d23a9

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,17 @@ private void resolveIndicesAndAnalyze(
566566
PreAnalysisResult result,
567567
ActionListener<Versioned<LogicalPlan>> logicalPlanListener
568568
) {
569-
SubscribableListener.<PreAnalysisResult>newForked(l -> preAnalyzeMainIndices(preAnalysis, executionInfo, result, requestFilter, l))
570-
.andThenApply(r -> {
571-
if (r.indexResolution.isEmpty() == false // Rule out ROW case with no FROM clauses
572-
&& executionInfo.isCrossClusterSearch()
573-
&& executionInfo.getRunningClusterAliases().findAny().isEmpty()) {
574-
LOGGER.debug("No more clusters to search, ending analysis stage");
575-
throw new NoClustersToSearchException();
576-
}
577-
return r;
578-
})
569+
SubscribableListener.<PreAnalysisResult>newForked(
570+
l -> preAnalyzeMainIndices(preAnalysis, configuration, executionInfo, result, requestFilter, l)
571+
).andThenApply(r -> {
572+
if (r.indexResolution.isEmpty() == false // Rule out ROW case with no FROM clauses
573+
&& executionInfo.isCrossClusterSearch()
574+
&& executionInfo.getRunningClusterAliases().findAny().isEmpty()) {
575+
LOGGER.debug("No more clusters to search, ending analysis stage");
576+
throw new NoClustersToSearchException();
577+
}
578+
return r;
579+
})
579580
.<PreAnalysisResult>andThen((l, r) -> preAnalyzeLookupIndices(preAnalysis.lookupIndices().iterator(), r, executionInfo, l))
580581
.<PreAnalysisResult>andThen((l, r) -> {
581582
enrichPolicyResolver.resolvePolicies(preAnalysis.enriches(), executionInfo, l.map(r::withEnrichResolution));
@@ -813,6 +814,7 @@ private void validateRemoteVersions(EsqlExecutionInfo executionInfo) {
813814
*/
814815
private void preAnalyzeMainIndices(
815816
PreAnalyzer.PreAnalysis preAnalysis,
817+
Configuration configuration,
816818
EsqlExecutionInfo executionInfo,
817819
PreAnalysisResult result,
818820
QueryBuilder requestFilter,
@@ -842,7 +844,16 @@ private void preAnalyzeMainIndices(
842844
forAll(
843845
preAnalysis.indexes().entrySet().iterator(),
844846
result,
845-
(e, r, l) -> preAnalyzeFlatMainIndices(e.getKey(), e.getValue(), preAnalysis, executionInfo, r, requestFilter, l),
847+
(e, r, l) -> preAnalyzeFlatMainIndices(
848+
e.getKey(),
849+
e.getValue(),
850+
configuration.projectRouting(),
851+
preAnalysis,
852+
executionInfo,
853+
r,
854+
requestFilter,
855+
l
856+
),
846857
listener
847858
);
848859
}
@@ -883,6 +894,7 @@ private void preAnalyzeMainIndices(
883894
private void preAnalyzeFlatMainIndices(
884895
IndexPattern indexPattern,
885896
IndexMode indexMode,
897+
String projectRouting,
886898
PreAnalyzer.PreAnalysis preAnalysis,
887899
EsqlExecutionInfo executionInfo,
888900
PreAnalysisResult result,
@@ -891,6 +903,7 @@ private void preAnalyzeFlatMainIndices(
891903
) {
892904
indexResolver.resolveFlatWorldIndicesVersioned(
893905
indexPattern.indexPattern(),
906+
projectRouting,
894907
result.fieldNames,
895908
createQueryFilter(indexMode, requestFilter),
896909
indexMode == IndexMode.TIME_SERIES,

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/IndexResolver.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public IndexResolver(Client client) {
102102
*/
103103
public void resolveIndices(String indexPattern, Set<String> fieldNames, ActionListener<IndexResolution> listener) {
104104
doResolveIndices(
105-
createFieldCapsRequest(DEFAULT_OPTIONS, indexPattern, fieldNames, null, false, false),
105+
createFieldCapsRequest(DEFAULT_OPTIONS, indexPattern, null, fieldNames, null, false, false),
106106
indexPattern,
107107
false,
108108
false,
@@ -126,7 +126,7 @@ public void resolveIndicesVersioned(
126126
ActionListener<Versioned<IndexResolution>> listener
127127
) {
128128
doResolveIndices(
129-
createFieldCapsRequest(DEFAULT_OPTIONS, indexPattern, fieldNames, requestFilter, includeAllDimensions, false),
129+
createFieldCapsRequest(DEFAULT_OPTIONS, indexPattern, null, fieldNames, requestFilter, includeAllDimensions, false),
130130
indexPattern,
131131
useAggregateMetricDoubleWhenNotSupported,
132132
useDenseVectorWhenNotSupported,
@@ -140,6 +140,7 @@ public void resolveIndicesVersioned(
140140

141141
public void resolveFlatWorldIndicesVersioned(
142142
String indexPattern,
143+
String projectRouting,
143144
Set<String> fieldNames,
144145
QueryBuilder requestFilter,
145146
boolean includeAllDimensions,
@@ -148,7 +149,7 @@ public void resolveFlatWorldIndicesVersioned(
148149
ActionListener<Versioned<IndexResolution>> listener
149150
) {
150151
doResolveIndices(
151-
createFieldCapsRequest(FLAT_WORLD_OPTIONS, indexPattern, fieldNames, requestFilter, includeAllDimensions, true),
152+
createFieldCapsRequest(FLAT_WORLD_OPTIONS, indexPattern, projectRouting, fieldNames, requestFilter, includeAllDimensions, true),
152153
indexPattern,
153154
useAggregateMetricDoubleWhenNotSupported,
154155
useDenseVectorWhenNotSupported,
@@ -478,6 +479,7 @@ private static EsField conflictingMetricTypes(String name, String fullName, Fiel
478479
private static FieldCapabilitiesRequest createFieldCapsRequest(
479480
IndicesOptions options,
480481
String index,
482+
@Nullable String projectRouting,
481483
Set<String> fieldNames,
482484
QueryBuilder requestFilter,
483485
boolean includeAllDimensions,
@@ -500,6 +502,7 @@ private static FieldCapabilitiesRequest createFieldCapsRequest(
500502
}
501503
request.setMergeResults(false);
502504
request.includeResolvedTo(includeResolvedTo);
505+
request.projectRouting(projectRouting);
503506
return request;
504507
}
505508

0 commit comments

Comments
 (0)