Skip to content

Commit d484828

Browse files
authored
If there's no matching index to wildcard, list it as success (#125173) (#125506)
* If there's no matching index to wildcard, list it as success
1 parent af3b29e commit d484828

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
341341
List.of(
342342
// local cluster is never marked as SKIPPED even when no matching indices - just marked as 0 shards searched
343343
new ExpectedCluster(LOCAL_CLUSTER, indexLoc, EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, localNumShards),
344-
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch*", EsqlExecutionInfo.Cluster.Status.SKIPPED, 0)
344+
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch*", EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, 0)
345345
)
346346
);
347347
}
@@ -358,7 +358,7 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
358358
List.of(
359359
// LIMIT 0 searches always have total shards = 0
360360
new ExpectedCluster(LOCAL_CLUSTER, indexLoc, EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, 0),
361-
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch*", EsqlExecutionInfo.Cluster.Status.SKIPPED, 0)
361+
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch*", EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, 0)
362362
)
363363
);
364364
}
@@ -506,13 +506,13 @@ public void testSearchesWhereNonExistentClusterIsSpecifiedWithWildcards() throws
506506
assertThat(executionInfo.isCrossClusterSearch(), is(true));
507507
assertThat(executionInfo.overallTook().millis(), greaterThanOrEqualTo(0L));
508508
assertThat(executionInfo.includeCCSMetadata(), equalTo(responseExpectMeta));
509-
assertThat(executionInfo.isPartial(), equalTo(true));
509+
assertThat(executionInfo.isPartial(), equalTo(false));
510510

511511
assertThat(executionInfo.clusterAliases(), equalTo(Set.of(REMOTE_CLUSTER_1, LOCAL_CLUSTER)));
512512

513513
EsqlExecutionInfo.Cluster remoteCluster = executionInfo.getCluster(REMOTE_CLUSTER_1);
514514
assertThat(remoteCluster.getIndexExpression(), equalTo("no_such_index*"));
515-
assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
515+
assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL));
516516
assertThat(remoteCluster.getTook().millis(), greaterThanOrEqualTo(0L));
517517
assertThat(remoteCluster.getTotalShards(), equalTo(0));
518518
assertThat(remoteCluster.getSuccessfulShards(), equalTo(0));

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.common.Strings;
1717
import org.elasticsearch.common.util.set.Sets;
1818
import org.elasticsearch.core.Nullable;
19-
import org.elasticsearch.core.TimeValue;
2019
import org.elasticsearch.indices.IndicesExpressionGrouper;
2120
import org.elasticsearch.license.XPackLicenseState;
2221
import org.elasticsearch.transport.ConnectTransportException;
@@ -219,29 +218,8 @@ static void updateExecutionInfoWithClustersWithNoMatchingIndices(EsqlExecutionIn
219218
fatalErrorMessage += "; " + error;
220219
}
221220
} else {
222-
// no matching indices and no concrete index requested - just skip it, no error
223-
EsqlExecutionInfo.Cluster.Status status;
224-
ShardSearchFailure failure;
225-
if (c.equals(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
226-
// never mark local cluster as SKIPPED
227-
status = EsqlExecutionInfo.Cluster.Status.SUCCESSFUL;
228-
failure = null;
229-
} else {
230-
status = EsqlExecutionInfo.Cluster.Status.SKIPPED;
231-
failure = new ShardSearchFailure(new VerificationException("Unknown index [" + indexExpression + "]"));
232-
}
233-
executionInfo.swapCluster(c, (k, v) -> {
234-
var builder = new EsqlExecutionInfo.Cluster.Builder(v).setStatus(status)
235-
.setTook(new TimeValue(0))
236-
.setTotalShards(0)
237-
.setSuccessfulShards(0)
238-
.setSkippedShards(0)
239-
.setFailedShards(0);
240-
if (failure != null) {
241-
builder.setFailures(List.of(failure));
242-
}
243-
return builder.build();
244-
});
221+
// no matching indices and no concrete index requested - just mark it as done, no error
222+
markClusterWithFinalStateAndNoShards(executionInfo, c, Cluster.Status.SUCCESSFUL, null);
245223
}
246224
}
247225
if (fatalErrorMessage != null) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ public void testUpdateExecutionInfoWithClustersWithNoMatchingIndices() {
308308

309309
EsqlExecutionInfo.Cluster remote1Cluster = executionInfo.getCluster(REMOTE1_ALIAS);
310310
assertThat(remote1Cluster.getIndexExpression(), equalTo("*"));
311-
assertThat(remote1Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
312-
assertThat(remote1Cluster.getTook().millis(), equalTo(0L));
311+
assertThat(remote1Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL));
312+
assertThat(remote1Cluster.getTook().millis(), greaterThanOrEqualTo(0L));
313313
assertThat(remote1Cluster.getTotalShards(), equalTo(0));
314314
assertThat(remote1Cluster.getSuccessfulShards(), equalTo(0));
315315
assertThat(remote1Cluster.getSkippedShards(), equalTo(0));
@@ -356,8 +356,8 @@ public void testUpdateExecutionInfoWithClustersWithNoMatchingIndices() {
356356

357357
EsqlExecutionInfo.Cluster remote2Cluster = executionInfo.getCluster(REMOTE2_ALIAS);
358358
assertThat(remote2Cluster.getIndexExpression(), equalTo("mylogs1*,mylogs2*,logs*"));
359-
assertThat(remote2Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
360-
assertThat(remote2Cluster.getTook().millis(), equalTo(0L));
359+
assertThat(remote2Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL));
360+
assertThat(remote2Cluster.getTook().millis(), greaterThanOrEqualTo(0L));
361361
assertThat(remote2Cluster.getTotalShards(), equalTo(0));
362362
assertThat(remote2Cluster.getSuccessfulShards(), equalTo(0));
363363
assertThat(remote2Cluster.getSkippedShards(), equalTo(0));

0 commit comments

Comments
 (0)