Skip to content

Commit a4d0012

Browse files
committed
test fixes
1 parent 374df05 commit a4d0012

File tree

3 files changed

+53
-39
lines changed

3 files changed

+53
-39
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryIT.java

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.esql.action;
99

1010
import org.elasticsearch.Build;
11+
import org.elasticsearch.ElasticsearchException;
1112
import org.elasticsearch.action.ActionListener;
1213
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1314
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
@@ -156,14 +157,10 @@ public void testSearchesAgainstNonMatchingIndicesWithLocalOnly() throws Exceptio
156157

157158
{
158159
String q = "FROM nomatch," + localIndex;
159-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> runQuery(q, false));
160-
assertThat(e.getDetailedMessage(), containsString("no such index [nomatch]"));
160+
expectNotFoundExceptionForQuery(q, "no such index [nomatch]", false);
161161

162-
// MP TODO: am I able to fix this from the field-caps call? Yes, if we detect concrete vs. wildcard expressions in user query
163-
// TODO bug - this does not throw; uncomment this test once https://github.com/elastic/elasticsearch/issues/114495 is fixed
164-
// String limit0 = q + " | LIMIT 0";
165-
// VerificationException ve = expectThrows(VerificationException.class, () -> runQuery(limit0, false));
166-
// assertThat(ve.getDetailedMessage(), containsString("No matching indices for [nomatch]"));
162+
String limit0 = q + " | LIMIT 0";
163+
expectNotFoundExceptionForQuery(limit0, "no such index [nomatch]", false);
167164
}
168165

169166
{
@@ -187,8 +184,8 @@ public void testSearchesAgainstNonMatchingIndicesWithLocalOnly() throws Exceptio
187184
}
188185
{
189186
String q = "FROM nomatch";
190-
String expectedError = "Unknown index [nomatch]";
191-
expectVerificationExceptionForQuery(q, expectedError, false);
187+
String expectedError = "no such index [nomatch]";
188+
expectNotFoundExceptionForQuery(q, expectedError, false);
192189
}
193190
{
194191
String q = "FROM nomatch*";
@@ -273,8 +270,8 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
273270
// missing concrete local index is an error
274271
{
275272
String q = "FROM nomatch,cluster-a:" + remote1Index;
276-
String expectedError = "Unknown index [nomatch]";
277-
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
273+
String expectedError = "no such index [nomatch]";
274+
expectNotFoundExceptionForQuery(q, expectedError, requestIncludeMeta);
278275
}
279276

280277
// missing concrete remote index is fatal
@@ -284,6 +281,13 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
284281
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
285282
}
286283

284+
// missing concrete remote index is fatal
285+
{
286+
String q = "FROM logs*,cluster-a:logs*,cluster-a:nomatch";
287+
String expectedError = "Unknown index [cluster-a:logs*,nomatch]";
288+
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
289+
}
290+
287291
// No error since local non-matching index has wildcard and the remote cluster index expression matches
288292
{
289293
String remote1IndexName = randomFrom(remote1Index, IDX_ALIAS, FILTERED_IDX_ALIAS);
@@ -368,8 +372,8 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
368372
// an error is thrown if there is a concrete index that does not match
369373
{
370374
String q = "FROM cluster-a:nomatch";
371-
String expectedError = "Unknown index [cluster-a:nomatch]";
372-
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
375+
String expectedError = "no such index [nomatch]";
376+
expectExceptionForQuery(q, expectedError, requestIncludeMeta, IndexNotFoundException.class);
373377
}
374378

375379
// an error is thrown if there are no matching indices at all - single remote cluster with wildcard index expression
@@ -382,8 +386,8 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
382386
// an error is thrown if there is a concrete index that does not match
383387
{
384388
String q = "FROM nomatch*,cluster-a:nomatch";
385-
String expectedError = "Unknown index [cluster-a:nomatch,nomatch*]";
386-
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
389+
String expectedError = "no such index [nomatch]";
390+
expectNotFoundExceptionForQuery(q, expectedError, requestIncludeMeta);
387391
}
388392

389393
// an error is thrown if there are no matching indices at all - local with wildcard, remote with wildcard
@@ -394,13 +398,13 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
394398
}
395399
{
396400
String q = "FROM nomatch,cluster-a:nomatch";
397-
String expectedError = "Unknown index [cluster-a:nomatch,nomatch]";
398-
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
401+
String expectedError = "no such index [nomatch]";
402+
expectNotFoundExceptionForQuery(q, expectedError, requestIncludeMeta);
399403
}
400404
{
401405
String q = "FROM nomatch,cluster-a:nomatch*";
402-
String expectedError = "Unknown index [cluster-a:nomatch*,nomatch]";
403-
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
406+
String expectedError = "no such index [nomatch]";
407+
expectNotFoundExceptionForQuery(q, expectedError, requestIncludeMeta);
404408
}
405409

406410
// --- test against 3 clusters
@@ -422,11 +426,32 @@ record ExpectedCluster(String clusterAlias, String indexExpression, EsqlExecutio
422426
* extra processing step to ensure that ESQL coordinator-only operations throw the same VerificationError.
423427
*/
424428
private void expectVerificationExceptionForQuery(String query, String error, Boolean requestIncludeMeta) {
425-
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(query, requestIncludeMeta));
429+
expectExceptionForQuery(query, error, requestIncludeMeta, VerificationException.class);
430+
}
431+
432+
/**
433+
* Runs the provided query, expecting a VerificationError. It then runs the same query with a "| LIMIT 0"
434+
* extra processing step to ensure that ESQL coordinator-only operations throw the same VerificationError.
435+
*/
436+
private void expectNotFoundExceptionForQuery(String query, String error, Boolean requestIncludeMeta) {
437+
expectExceptionForQuery(query, error, requestIncludeMeta, IndexNotFoundException.class);
438+
}
439+
440+
/**
441+
* Runs the provided query, expecting a VerificationError. It then runs the same query with a "| LIMIT 0"
442+
* extra processing step to ensure that ESQL coordinator-only operations throw the same VerificationError.
443+
*/
444+
private <ET extends ElasticsearchException> void expectExceptionForQuery(
445+
String query,
446+
String error,
447+
Boolean requestIncludeMeta,
448+
Class<ET> clazz
449+
) {
450+
ET e = expectThrows(clazz, () -> runQuery(query, requestIncludeMeta));
426451
assertThat(e.getDetailedMessage(), containsString(error));
427452

428453
String limit0 = query + " | LIMIT 0";
429-
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta));
454+
e = expectThrows(clazz, () -> runQuery(limit0, requestIncludeMeta));
430455
assertThat(e.getDetailedMessage(), containsString(error));
431456
}
432457

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.elasticsearch.xpack.esql.plugin;
99

10-
import org.elasticsearch.ExceptionsHelper;
1110
import org.elasticsearch.action.ActionListener;
1211
import org.elasticsearch.action.ActionListenerResponseHandler;
1312
import org.elasticsearch.action.OriginalIndices;
@@ -17,7 +16,6 @@
1716
import org.elasticsearch.compute.operator.exchange.ExchangeSourceHandler;
1817
import org.elasticsearch.core.Releasable;
1918
import org.elasticsearch.core.TimeValue;
20-
import org.elasticsearch.index.IndexNotFoundException;
2119
import org.elasticsearch.tasks.CancellableTask;
2220
import org.elasticsearch.tasks.Task;
2321
import org.elasticsearch.tasks.TaskCancelledException;
@@ -90,18 +88,12 @@ void startComputeOnRemoteCluster(
9088
if (receivedResults == false && EsqlCCSUtils.shouldIgnoreRuntimeError(executionInfo, clusterAlias, e)) {
9189
EsqlCCSUtils.markClusterWithFinalStateAndNoShards(executionInfo, clusterAlias, EsqlExecutionInfo.Cluster.Status.SKIPPED, e);
9290
l.onResponse(List.of());
93-
} else if (configuration.allowPartialResults()
94-
&& (ExceptionsHelper.unwrapCause(e) instanceof IndexNotFoundException) == false) {
95-
EsqlCCSUtils.markClusterWithFinalStateAndNoShards(
96-
executionInfo,
97-
clusterAlias,
98-
EsqlExecutionInfo.Cluster.Status.PARTIAL,
99-
e
100-
);
101-
l.onResponse(List.of());
102-
} else {
103-
l.onFailure(e);
104-
}
91+
} else if (configuration.allowPartialResults()) {
92+
EsqlCCSUtils.markClusterWithFinalStateAndNoShards(executionInfo, clusterAlias, EsqlExecutionInfo.Cluster.Status.PARTIAL, e);
93+
l.onResponse(List.of());
94+
} else {
95+
l.onFailure(e);
96+
}
10597
});
10698
ExchangeService.openExchange(
10799
transportService,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.elasticsearch.xpack.esql.plugin;
99

10-
import org.elasticsearch.ExceptionsHelper;
1110
import org.elasticsearch.action.ActionListener;
1211
import org.elasticsearch.action.OriginalIndices;
1312
import org.elasticsearch.action.search.SearchRequest;
@@ -29,7 +28,6 @@
2928
import org.elasticsearch.core.Releasables;
3029
import org.elasticsearch.core.TimeValue;
3130
import org.elasticsearch.core.Tuple;
32-
import org.elasticsearch.index.IndexNotFoundException;
3331
import org.elasticsearch.index.query.SearchExecutionContext;
3432
import org.elasticsearch.logging.LogManager;
3533
import org.elasticsearch.logging.Logger;
@@ -320,8 +318,7 @@ public void execute(
320318
);
321319
dataNodesListener.onResponse(r.getProfiles());
322320
}, e -> {
323-
if (configuration.allowPartialResults()
324-
&& (ExceptionsHelper.unwrapCause(e) instanceof IndexNotFoundException) == false) {
321+
if (configuration.allowPartialResults()) {
325322
execInfo.swapCluster(
326323
LOCAL_CLUSTER,
327324
(k, v) -> new EsqlExecutionInfo.Cluster.Builder(v).setStatus(

0 commit comments

Comments
 (0)