Skip to content
Closed
Show file tree
Hide file tree
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 @@ -73,21 +73,23 @@ public void wipeTestData() throws IOException {
}
}

private String getInexistentIndexErrorMessage() {
return "\"reason\" : \"Found 1 problem\\nline 1:1: Unknown index ";
}

public void testInexistentIndexNameWithWildcard() throws IOException {
assertErrorMessages(inexistentIndexNameWithWildcard, getInexistentIndexErrorMessage(), 400);
for (String indexName : inexistentIndexNameWithWildcard) {
assertErrorMessage(indexName, "Unknown index " + "[" + clusterSpecificIndexName(indexName) + "]", 400);
}
}

@AwaitsFix(bugUrl = "TBD")
// field caps report only first missing index
public void testInexistentIndexNameWithoutWildcard() throws IOException {
assertErrorMessages(inexistentIndexNameWithoutWildcard, getInexistentIndexErrorMessage(), 400);
for (String indexName : inexistentIndexNameWithoutWildcard) {
assertErrorMessage(indexName, "Unknown index " + "[" + clusterSpecificIndexName(indexName) + "]", 400);
}
}

public void testExistentIndexWithoutWildcard() throws IOException {
for (String indexName : existentIndexWithoutWildcard) {
assertErrorMessage(indexName, "\"reason\" : \"no such index [inexistent]\"", 404);
assertErrorMessage(indexName, "Unknown index [inexistent]", 400);
}
}

Expand All @@ -99,19 +101,13 @@ public void testAlias() throws IOException {
createAlias();

for (String indexName : existentAliasWithoutWildcard) {
assertErrorMessage(indexName, "\"reason\" : \"no such index [inexistent]\"", 404);
assertErrorMessage(indexName, "Unknown index [inexistent]", 400);
}
assertValidRequestOnIndices(existentAliasWithWildcard);

deleteAlias();
}

private void assertErrorMessages(String[] indices, String errorMessage, int statusCode) throws IOException {
for (String indexName : indices) {
assertErrorMessage(indexName, errorMessage + "[" + clusterSpecificIndexName(indexName) + "]", statusCode);
}
}

protected String clusterSpecificIndexName(String indexName) {
return indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public void testIndicesDontExist() throws IOException {
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]"));
assertEquals(400, e.getResponse().getStatusLine().getStatusCode());
assertThat(e.getMessage(), containsString("verification_exception"));
assertThat(e.getMessage(), containsString("Unknown index [foo]"));

// Don't test remote patterns here, we'll test them in the multi-cluster tests
if (EsqlCapabilities.Cap.JOIN_LOOKUP_V12.isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.datastreams.DataStreamsPlugin;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.esql.VerificationException;
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
Expand Down Expand Up @@ -200,22 +199,18 @@ public void testUnavailableIndex() {
}

public void testPartialResolution() {
assertAcked(client().admin().indices().prepareCreate("index-1"));
assertAcked(client().admin().indices().prepareCreate("index-2"));
indexRandom(true, "index-2", 10);
assertAcked(client().admin().indices().prepareCreate("data"));
indexRandom(true, "data", 10);

try (var response = run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1"))) {
assertOk(response); // okay when present index is empty
}
expectThrows(
IndexNotFoundException.class,
equalTo("no such index [nonexisting-1]"), // fails when present index is non-empty
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1"))
VerificationException.class,
containsString("Unknown index [nonexisting-1]"),
() -> run(syncEsqlQueryRequest().query("FROM data,nonexisting-1"))
);
expectThrows(
IndexNotFoundException.class,
equalTo("no such index [nonexisting-1]"), // only the first missing index is reported
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1,nonexisting-2"))
VerificationException.class,
containsString("Unknown index [nonexisting-1]"), // only the first missing index is reported
() -> run(syncEsqlQueryRequest().query("FROM data,nonexisting-1,nonexisting-2"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.esql.session;

import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesIndexResponse;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
Expand All @@ -16,6 +17,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.mapper.TimeSeriesParams;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -56,7 +58,7 @@ public class IndexResolver {
public static final String UNMAPPED = "unmapped";

public static final IndicesOptions FIELD_CAPS_INDICES_OPTIONS = IndicesOptions.builder()
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS)
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS)
.wildcardOptions(
IndicesOptions.WildcardOptions.builder()
.matchOpen(true)
Expand Down Expand Up @@ -91,10 +93,19 @@ public void resolveAsMergedMapping(
client.execute(
EsqlResolveFieldsAction.TYPE,
createFieldCapsRequest(indexWildcard, fieldNames, requestFilter, includeAllDimensions),
listener.delegateFailureAndWrap(
(l, response) -> l.onResponse(
mergedMappings(indexWildcard, new FieldsInfo(response, supportsAggregateMetricDouble, supportsDenseVector))
)
ActionListener.wrap(
r -> listener.onResponse(
mergedMappings(indexWildcard, new FieldsInfo(r, supportsAggregateMetricDouble, supportsDenseVector))
),
f -> {
if (f instanceof IndexNotFoundException e) {
listener.onResponse(IndexResolution.notFound(e.getIndex().getName()));
} else if (f instanceof ElasticsearchSecurityException e) {
listener.onResponse(IndexResolution.notFound(indexWildcard));
} else {
listener.onFailure(f);
}
}
)
);
}
Expand Down