diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java index c711a99344102..f50091e164086 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/IndexResolutionIT.java @@ -18,6 +18,8 @@ import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.datastreams.DataStreamsPlugin; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.query.MatchAllQueryBuilder; +import org.elasticsearch.index.query.MatchNoneQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.esql.VerificationException; import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; @@ -96,11 +98,24 @@ public void testResolvesPattern() { } } - public void testDoesNotResolveMissingIndex() { + public void testResolvesExclusionPattern() { + assertAcked(client().admin().indices().prepareCreate("index-1")); + indexRandom(true, "index-1", 1); + assertAcked(client().admin().indices().prepareCreate("index-2")); + indexRandom(true, "index-2", 1); + + try (var response = run(syncEsqlQueryRequest().query("FROM index*,-index-2 METADATA _index"))) { + assertOk(response); + assertResultConcreteIndices(response, "index-1");// excludes concrete index from pattern + } + try (var response = run(syncEsqlQueryRequest().query("FROM index*,-*2 METADATA _index"))) { + assertOk(response); + assertResultConcreteIndices(response, "index-1");// excludes pattern from pattern + } expectThrows( VerificationException.class, - containsString("Unknown index [no-such-index]"), - () -> run(syncEsqlQueryRequest().query("FROM no-such-index")) + containsString("Unknown index [index-*,-*]"), + () -> run(syncEsqlQueryRequest().query("FROM index-*,-* METADATA _index")) // exclude all resolves to empty ); } @@ -120,6 +135,14 @@ public void testDoesNotResolveEmptyPattern() { } } + public void testDoesNotResolveUnknownIndex() { + expectThrows( + VerificationException.class, + containsString("Unknown index [no-such-index]"), + () -> run(syncEsqlQueryRequest().query("FROM no-such-index")) + ); + } + public void testDoesNotResolveClosedIndex() { assertAcked(client().admin().indices().prepareCreate("index-1")); indexRandom(true, "index-1", 1); @@ -219,6 +242,20 @@ public void testPartialResolution() { ); } + public void testResolutionWithFilter() { + assertAcked(client().admin().indices().prepareCreate("data")); + indexRandom(true, "data", 1); + + try (var response = run(syncEsqlQueryRequest().query("FROM data METADATA _index").filter(new MatchAllQueryBuilder()))) { + assertOk(response); + assertResultConcreteIndices(response, "data"); + } + try (var response = run(syncEsqlQueryRequest().query("FROM data METADATA _index").filter(new MatchNoneQueryBuilder()))) { + assertOk(response); + assertResultConcreteIndices(response); + } + } + private static void assertOk(EsqlQueryResponse response) { assertThat(response.isPartial(), equalTo(false)); }