Skip to content

Commit 3029bfb

Browse files
committed
resolve using original index pattern
1 parent b1e75f4 commit 3029bfb

File tree

3 files changed

+19
-107
lines changed

3 files changed

+19
-107
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,6 @@ static void updateExecutionInfoToReturnEmptyResult(EsqlExecutionInfo executionIn
156156
}
157157
}
158158

159-
static String createIndexExpressionFromAvailableClusters(EsqlExecutionInfo executionInfo) {
160-
StringBuilder sb = new StringBuilder();
161-
for (String clusterAlias : executionInfo.clusterAliases()) {
162-
EsqlExecutionInfo.Cluster cluster = executionInfo.getCluster(clusterAlias);
163-
// Exclude clusters which are either skipped or have no indices matching wildcard, or filtered out.
164-
if (cluster.getStatus() != Cluster.Status.SKIPPED && cluster.getStatus() != Cluster.Status.SUCCESSFUL) {
165-
if (cluster.getClusterAlias().equals(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
166-
sb.append(executionInfo.getCluster(clusterAlias).getIndexExpression()).append(',');
167-
} else {
168-
String indexExpression = executionInfo.getCluster(clusterAlias).getIndexExpression();
169-
for (String index : indexExpression.split(",")) {
170-
sb.append(clusterAlias).append(':').append(index).append(',');
171-
}
172-
}
173-
}
174-
}
175-
176-
if (sb.length() > 0) {
177-
return sb.substring(0, sb.length() - 1);
178-
} else {
179-
return "";
180-
}
181-
}
182-
183159
static String createQualifiedLookupIndexExpressionFromAvailableClusters(EsqlExecutionInfo executionInfo, String localPattern) {
184160
if (executionInfo.getClusters().isEmpty()) {
185161
return localPattern;

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -647,33 +647,25 @@ private void preAnalyzeMainIndices(
647647
ThreadPool.Names.SYSTEM_READ
648648
);
649649
if (preAnalysis.indexPattern() != null) {
650-
String indexExpressionToResolve = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo);
651-
if (indexExpressionToResolve.isEmpty()) {
652-
// if this was a pure remote CCS request (no local indices) and all remotes are offline, return an empty IndexResolution
653-
listener.onResponse(
654-
result.withIndices(IndexResolution.valid(new EsIndex(preAnalysis.indexPattern().indexPattern(), Map.of(), Map.of())))
655-
);
656-
} else {
657-
indexResolver.resolveAsMergedMapping(
658-
indexExpressionToResolve,
659-
result.fieldNames,
660-
// Maybe if no indices are returned, retry without index mode and provide a clearer error message.
661-
switch (preAnalysis.indexMode()) {
662-
case IndexMode.TIME_SERIES -> {
663-
var indexModeFilter = new TermQueryBuilder(IndexModeFieldMapper.NAME, IndexMode.TIME_SERIES.getName());
664-
yield requestFilter != null
665-
? new BoolQueryBuilder().filter(requestFilter).filter(indexModeFilter)
666-
: indexModeFilter;
667-
}
668-
default -> requestFilter;
669-
},
670-
preAnalysis.indexMode() == IndexMode.TIME_SERIES,
671-
listener.delegateFailureAndWrap((l, indexResolution) -> {
672-
EsqlCCSUtils.updateExecutionInfoWithUnavailableClusters(executionInfo, indexResolution.failures());
673-
l.onResponse(result.withIndices(indexResolution));
674-
})
675-
);
676-
}
650+
indexResolver.resolveAsMergedMapping(
651+
preAnalysis.indexPattern().indexPattern(),
652+
result.fieldNames,
653+
// Maybe if no indices are returned, retry without index mode and provide a clearer error message.
654+
switch (preAnalysis.indexMode()) {
655+
case IndexMode.TIME_SERIES -> {
656+
var indexModeFilter = new TermQueryBuilder(IndexModeFieldMapper.NAME, IndexMode.TIME_SERIES.getName());
657+
yield requestFilter != null
658+
? new BoolQueryBuilder().filter(requestFilter).filter(indexModeFilter)
659+
: indexModeFilter;
660+
}
661+
default -> requestFilter;
662+
},
663+
preAnalysis.indexMode() == IndexMode.TIME_SERIES,
664+
listener.delegateFailureAndWrap((l, indexResolution) -> {
665+
EsqlCCSUtils.updateExecutionInfoWithUnavailableClusters(executionInfo, indexResolution.failures());
666+
l.onResponse(result.withIndices(indexResolution));
667+
})
668+
);
677669
} else {
678670
// occurs when dealing with local relations (row a = 1)
679671
listener.onResponse(result.withIndices(IndexResolution.invalid("[none specified]")));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,62 +59,6 @@ public class EsqlCCSUtilsTests extends ESTestCase {
5959
private final String REMOTE1_ALIAS = "remote1";
6060
private final String REMOTE2_ALIAS = "remote2";
6161

62-
public void testCreateIndexExpressionFromAvailableClusters() {
63-
var skipped = EsqlExecutionInfo.Cluster.Status.SKIPPED;
64-
// no clusters marked as skipped
65-
{
66-
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
67-
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*", false));
68-
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*", true));
69-
executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true));
70-
assertIndexPattern(
71-
EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo),
72-
containsInAnyOrder("logs*", "remote1:*", "remote2:mylogs1", "remote2:mylogs2", "remote2:logs*")
73-
);
74-
}
75-
76-
// one cluster marked as skipped, so not present in revised index expression
77-
{
78-
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
79-
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*", false));
80-
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true));
81-
executionInfo.swapCluster(
82-
REMOTE2_ALIAS,
83-
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
84-
);
85-
assertIndexPattern(
86-
EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo),
87-
containsInAnyOrder("logs*", "remote1:*", "remote1:foo")
88-
);
89-
}
90-
91-
// two clusters marked as skipped, so only local cluster present in revised index expression
92-
{
93-
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
94-
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*", false));
95-
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true, skipped));
96-
executionInfo.swapCluster(
97-
REMOTE2_ALIAS,
98-
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
99-
);
100-
assertThat(EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo), equalTo("logs*"));
101-
}
102-
103-
// only remotes present and all marked as skipped, so in revised index expression should be empty string
104-
{
105-
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
106-
executionInfo.swapCluster(
107-
REMOTE1_ALIAS,
108-
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true, EsqlExecutionInfo.Cluster.Status.SKIPPED)
109-
);
110-
executionInfo.swapCluster(
111-
REMOTE2_ALIAS,
112-
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
113-
);
114-
assertThat(EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo), equalTo(""));
115-
}
116-
}
117-
11862
public void testCreateQualifiedLookupIndexExpressionFromAvailableClusters() {
11963

12064
var skipped = EsqlExecutionInfo.Cluster.Status.SKIPPED;

0 commit comments

Comments
 (0)