Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}

Expand All @@ -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"))
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is existing test case, it was moved down


public void testDoesNotResolveClosedIndex() {
assertAcked(client().admin().indices().prepareCreate("index-1"));
indexRandom(true, "index-1", 1);
Expand Down Expand Up @@ -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));
}
Expand Down