-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Fix ESQL index resolution #135826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix ESQL index resolution #135826
Changes from 4 commits
5bf94ba
4f4f327
d3cd665
675b7c2
b0a563c
555c294
82459d9
d30da96
cc5fec5
f4d565f
237b470
5c2dec8
b92deb6
965343d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,15 +85,11 @@ public void testTimestampFilterFromQuery() throws IOException { | |
allOf(instanceOf(List.class), hasSize(docsTest1)) | ||
); | ||
|
||
// filter excludes both indices (no rows); the first analysis step fails because there are no columns, a second attempt succeeds | ||
// after eliminating the index filter. All columns are returned. | ||
// filter excludes both indices (no rows); Empty result set is derived. | ||
builder = timestampFilter("gte", "2025-01-01").query(from("test*")); | ||
assertQueryResult( | ||
runEsql(builder), | ||
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date")) | ||
.item(matchesMap().entry("name", "id1").entry("type", "integer")) | ||
.item(matchesMap().entry("name", "id2").entry("type", "integer")) | ||
.item(matchesMap().entry("name", "value").entry("type", "long")), | ||
matchesList().item(matchesMap().entry("name", "<no-fields>").entry("type", "null")), | ||
allOf(instanceOf(List.class), hasSize(0)) | ||
); | ||
} | ||
|
@@ -206,15 +202,10 @@ public void testIndicesDontExist() throws IOException { | |
assertThat(e.getMessage(), containsString("verification_exception")); | ||
assertThat(e.getMessage(), anyOf(containsString("Unknown index [foo]"), containsString("Unknown index [remote_cluster:foo]"))); | ||
|
||
e = expectThrows(ResponseException.class, () -> runEsql(timestampFilter("gte", "2020-01-01").query(from("foo*")))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same, foo* can now expand to empty result set |
||
e = expectThrows(ResponseException.class, () -> runEsql(timestampFilter("gte", "2020-01-01").query("FROM foo,test1"))); | ||
assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(e.getMessage(), containsString("verification_exception")); | ||
assertThat(e.getMessage(), anyOf(containsString("Unknown index [foo*]"), containsString("Unknown index [remote_cluster:foo*]"))); | ||
|
||
e = expectThrows(ResponseException.class, () -> runEsql(timestampFilter("gte", "2020-01-01").query("FROM foo, test1"))); | ||
assertEquals(404, e.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(e.getMessage(), containsString("index_not_found_exception")); | ||
assertThat(e.getMessage(), containsString("no such index [foo]")); | ||
assertThat(e.getMessage(), containsString("Unknown index [foo,test1]"));// TODO why test1 is reported? | ||
|
||
// Don't test remote patterns here, we'll test them in the multi-cluster tests | ||
if (EsqlCapabilities.Cap.JOIN_LOOKUP_V12.isEnabled()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
import org.elasticsearch.compute.operator.DriverProfile; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.core.Tuple; | ||
import org.elasticsearch.index.IndexNotFoundException; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.TermsQueryBuilder; | ||
import org.elasticsearch.test.FailingFieldPlugin; | ||
|
@@ -133,15 +132,10 @@ public void testSearchesAgainstNonMatchingIndicesWithLocalOnly() throws Exceptio | |
|
||
{ | ||
String q = "FROM nomatch," + localIndex; | ||
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> runQuery(q, false)); | ||
assertThat(e.getDetailedMessage(), containsString("no such index [nomatch]")); | ||
|
||
// MP TODO: am I able to fix this from the field-caps call? Yes, if we detect concrete vs. wildcard expressions in user query | ||
// TODO bug - this does not throw; uncomment this test once this is fixed: | ||
// AwaitsFix https://github.com/elastic/elasticsearch/issues/114495 | ||
// String limit0 = q + " | LIMIT 0"; | ||
// VerificationException ve = expectThrows(VerificationException.class, () -> runQuery(limit0, false)); | ||
// assertThat(ve.getDetailedMessage(), containsString("No matching indices for [nomatch]")); | ||
expectThrows(VerificationException.class, containsString("Unknown index [nomatch]"), () -> runQuery(q, false)); | ||
|
||
String limit0 = q + " | LIMIT 0"; | ||
expectThrows(VerificationException.class, containsString("Unknown index [nomatch]"), () -> runQuery(limit0, false)); | ||
} | ||
|
||
{ | ||
|
@@ -168,11 +162,6 @@ public void testSearchesAgainstNonMatchingIndicesWithLocalOnly() throws Exceptio | |
String expectedError = "Unknown index [nomatch]"; | ||
expectVerificationExceptionForQuery(q, expectedError, false); | ||
} | ||
{ | ||
String q = "FROM nomatch*"; | ||
String expectedError = "Unknown index [nomatch*]"; | ||
expectVerificationExceptionForQuery(q, expectedError, false); | ||
} | ||
} | ||
|
||
public void testSearchesAgainstIndicesWithNoMappingsSkipUnavailableTrue() throws Exception { | ||
|
@@ -234,10 +223,6 @@ public void testSearchesAgainstIndicesWithNoMappingsSkipUnavailableTrue() throws | |
} | ||
|
||
public void testSearchesAgainstNonMatchingIndices() throws Exception { | ||
testSearchesAgainstNonMatchingIndices(true); | ||
} | ||
|
||
protected void testSearchesAgainstNonMatchingIndices(boolean exceptionWithSkipUnavailableFalse) throws Exception { | ||
int numClusters = 3; | ||
Map<String, Object> testClusterInfo = setupClusters(numClusters); | ||
int localNumShards = (Integer) testClusterInfo.get("local.num_shards"); | ||
|
@@ -264,11 +249,9 @@ protected void testSearchesAgainstNonMatchingIndices(boolean exceptionWithSkipUn | |
{ | ||
String q = "FROM logs*,cluster-a:nomatch"; | ||
String expectedError = "Unknown index [cluster-a:nomatch]"; | ||
if (exceptionWithSkipUnavailableFalse) { | ||
setSkipUnavailable(REMOTE_CLUSTER_1, false); | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
setSkipUnavailable(REMOTE_CLUSTER_1, true); | ||
} | ||
setSkipUnavailable(REMOTE_CLUSTER_1, false); | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
setSkipUnavailable(REMOTE_CLUSTER_1, true); | ||
try (EsqlQueryResponse resp = runQuery(q, requestIncludeMeta)) { | ||
assertThat(getValuesList(resp).size(), greaterThanOrEqualTo(1)); | ||
EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); | ||
|
@@ -370,14 +353,7 @@ protected void testSearchesAgainstNonMatchingIndices(boolean exceptionWithSkipUn | |
{ | ||
String q = "FROM cluster-a:nomatch"; | ||
String expectedError = "Unknown index [cluster-a:nomatch]"; | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
} | ||
|
||
// an error is thrown if there are no matching indices at all - single remote cluster with wildcard index expression | ||
{ | ||
String q = "FROM cluster-a:nomatch*"; | ||
String expectedError = "Unknown index [cluster-a:nomatch*]"; | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);// TODO this must contain the remote cluster alias | ||
|
||
} | ||
|
||
// an error is thrown if there is a concrete index that does not match | ||
|
@@ -412,11 +388,9 @@ protected void testSearchesAgainstNonMatchingIndices(boolean exceptionWithSkipUn | |
String remote2IndexName = randomFrom(remote2Index, IDX_ALIAS, FILTERED_IDX_ALIAS); | ||
String q = Strings.format("FROM %s*,cluster-a:nomatch,%s:%s*", localIndexName, REMOTE_CLUSTER_2, remote2IndexName); | ||
String expectedError = "Unknown index [cluster-a:nomatch]"; | ||
if (exceptionWithSkipUnavailableFalse) { | ||
setSkipUnavailable(REMOTE_CLUSTER_1, false); | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
setSkipUnavailable(REMOTE_CLUSTER_1, true); | ||
} | ||
setSkipUnavailable(REMOTE_CLUSTER_1, false); | ||
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta); | ||
setSkipUnavailable(REMOTE_CLUSTER_1, true); | ||
try (EsqlQueryResponse resp = runQuery(q, requestIncludeMeta)) { | ||
assertThat(getValuesList(resp).size(), greaterThanOrEqualTo(1)); | ||
EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); | ||
|
@@ -452,12 +426,8 @@ record ExpectedCluster(String clusterAlias, String indexExpression, EsqlExecutio | |
* extra processing step to ensure that ESQL coordinator-only operations throw the same VerificationError. | ||
*/ | ||
protected void expectVerificationExceptionForQuery(String query, String error, Boolean requestIncludeMeta) { | ||
VerificationException e = expectThrows(VerificationException.class, () -> runQuery(query, requestIncludeMeta)); | ||
assertThat(e.getDetailedMessage(), containsString(error)); | ||
|
||
String limit0 = query + " | LIMIT 0"; | ||
e = expectThrows(VerificationException.class, () -> runQuery(limit0, requestIncludeMeta)); | ||
assertThat(e.getDetailedMessage(), containsString(error)); | ||
expectThrows(VerificationException.class, containsString(error), () -> runQuery(query, requestIncludeMeta)); | ||
expectThrows(VerificationException.class, containsString(error), () -> runQuery(query + " | LIMIT 0", requestIncludeMeta)); | ||
} | ||
|
||
public void assertExpectedClustersForMissingIndicesTests(EsqlExecutionInfo executionInfo, List<ExpectedCluster> expected) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now wildcards are allowed to expand to empty result set