Skip to content

Commit f52205a

Browse files
committed
Make index resolution required
1 parent 9316d64 commit f52205a

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.common.settings.Settings;
1818
import org.elasticsearch.common.util.CollectionUtils;
1919
import org.elasticsearch.datastreams.DataStreamsPlugin;
20-
import org.elasticsearch.index.IndexNotFoundException;
2120
import org.elasticsearch.plugins.Plugin;
2221
import org.elasticsearch.xpack.esql.VerificationException;
2322
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
@@ -196,17 +195,19 @@ public void testPartialResolution() {
196195
assertAcked(client().admin().indices().prepareCreate("index-2"));
197196
indexRandom(true, "index-2", 10);
198197

199-
try (var response = run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1"))) {
200-
assertOk(response); // okay when present index is empty
201-
}
202198
expectThrows(
203-
IndexNotFoundException.class,
204-
equalTo("no such index [nonexisting-1]"), // fails when present index is non-empty
199+
VerificationException.class,
200+
containsString("Unknown index [nonexisting-1]"), // fails when present index is empty
201+
() -> run(syncEsqlQueryRequest().query("FROM index-1,nonexisting-1"))
202+
);
203+
expectThrows(
204+
VerificationException.class,
205+
containsString("Unknown index [nonexisting-1]"), // fails when present index is non-empty
205206
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1"))
206207
);
207208
expectThrows(
208-
IndexNotFoundException.class,
209-
equalTo("no such index [nonexisting-1]"), // only the first missing index is reported
209+
VerificationException.class,
210+
containsString("Unknown index [nonexisting-1]"), // only the first missing index is reported
210211
() -> run(syncEsqlQueryRequest().query("FROM index-2,nonexisting-1,nonexisting-2"))
211212
);
212213
}

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.Strings;
1717
import org.elasticsearch.common.util.Maps;
1818
import org.elasticsearch.index.IndexMode;
19+
import org.elasticsearch.index.IndexNotFoundException;
1920
import org.elasticsearch.index.mapper.TimeSeriesParams;
2021
import org.elasticsearch.index.query.QueryBuilder;
2122
import org.elasticsearch.threadpool.ThreadPool;
@@ -56,7 +57,7 @@ public class IndexResolver {
5657
public static final String UNMAPPED = "unmapped";
5758

5859
public static final IndicesOptions FIELD_CAPS_INDICES_OPTIONS = IndicesOptions.builder()
59-
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS)
60+
.concreteTargetOptions(IndicesOptions.ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS)
6061
.wildcardOptions(
6162
IndicesOptions.WildcardOptions.builder()
6263
.matchOpen(true)
@@ -91,11 +92,34 @@ public void resolveAsMergedMapping(
9192
client.execute(
9293
EsqlResolveFieldsAction.TYPE,
9394
createFieldCapsRequest(indexWildcard, fieldNames, requestFilter, includeAllDimensions),
94-
listener.delegateFailureAndWrap(
95-
(l, response) -> l.onResponse(
96-
mergedMappings(indexWildcard, new FieldsInfo(response, supportsAggregateMetricDouble, supportsDenseVector))
97-
)
95+
ActionListener.wrap(
96+
r -> listener.onResponse(
97+
mergedMappings(indexWildcard, new FieldsInfo(r, supportsAggregateMetricDouble, supportsDenseVector))
98+
),
99+
f -> {
100+
if (f instanceof IndexNotFoundException e) {
101+
listener.onResponse(IndexResolution.notFound(e.getIndex().getName()));
102+
} else {
103+
listener.onFailure(f);
104+
}
105+
}
98106
)
107+
// new ActionListener<FieldCapabilitiesResponse>() {
108+
// @Override
109+
// public void onResponse(FieldCapabilitiesResponse fieldCapabilitiesResponse) {
110+
//
111+
// }
112+
//
113+
// @Override
114+
// public void onFailure(Exception e) {
115+
//
116+
// }
117+
// }
118+
// listener.delegateFailureAndWrap(
119+
// (l, response) -> l.onResponse(
120+
// mergedMappings(indexWildcard, new FieldsInfo(response, supportsAggregateMetricDouble, supportsDenseVector))
121+
// )
122+
// )
99123
);
100124
}
101125

0 commit comments

Comments
 (0)