Skip to content

Commit 3956365

Browse files
Improve error messages for _stats with closed indices (opensearch-project#13012) (opensearch-project#13338)
1 parent fd89920 commit 3956365

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5656
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
5757
- Enabled mockTelemetryPlugin for IT and fixed OOM issues ([#13054](https://github.com/opensearch-project/OpenSearch/pull/13054))
5858
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
59-
- Fix snapshot _status API to return correct status for partial snapshots ([#13260](https://github.com/opensearch-project/OpenSearch/pull/13260))
59+
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
60+
- Improve the error messages for _stats with closed indices ([#13012](https://github.com/opensearch-project/OpenSearch/pull/13012))
6061
- Ignore BaseRestHandler unconsumed content check as it's always consumed. ([#13290](https://github.com/opensearch-project/OpenSearch/pull/13290))
6162

6263
### Security

modules/rank-eval/src/internalClusterTest/java/org/opensearch/index/rankeval/RankEvalRequestIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public void testIndicesOptions() {
345345
request.indicesOptions(IndicesOptions.fromParameters("closed", null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
346346
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
347347
assertEquals(1, response.getFailures().size());
348-
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IndexClosedException.class));
348+
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IllegalArgumentException.class));
349349

350350
// test allow_no_indices
351351
request = new RankEvalRequest(task, new String[] { "bad*" });

server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,13 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set<Inde
383383
private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, IndexMetadata index) {
384384
if (index.getState() == IndexMetadata.State.CLOSE) {
385385
if (options.forbidClosedIndices() && options.ignoreUnavailable() == false) {
386-
throw new IndexClosedException(index.getIndex());
386+
if (options.expandWildcardsClosed() == true && options.getExpandWildcards().size() == 1) {
387+
throw new IllegalArgumentException(
388+
"To expand [" + index.getState() + "] wildcard, please set forbid_closed_indices to `false`"
389+
);
390+
} else {
391+
throw new IndexClosedException(index.getIndex());
392+
}
387393
} else {
388394
return options.forbidClosedIndices() == false && addIndex(index, context);
389395
}

server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,25 @@ public void testIndexOptionsWildcardExpansion() {
352352
assertEquals(1, results.length);
353353
assertThat(results, arrayContainingInAnyOrder(".hidden-closed"));
354354

355+
options = IndicesOptions.fromOptions(false, true, false, true, false, false, false, false);
356+
context = new IndexNameExpressionResolver.Context(state, options, false);
357+
358+
results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
359+
assertEquals(1, results.length);
360+
assertEquals("foo", results[0]);
361+
362+
try {
363+
options = IndicesOptions.fromOptions(false, true, false, true, false, true, false, false);
364+
context = new IndexNameExpressionResolver.Context(state, options, false);
365+
366+
results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
367+
assertEquals(1, results.length);
368+
assertEquals("foo", results[0]);
369+
} catch (IllegalArgumentException iae) {
370+
String expectedMessage = "To expand [CLOSE] wildcard, please set forbid_closed_indices to `false`";
371+
assertEquals(expectedMessage, iae.getMessage());
372+
}
373+
355374
// Only open
356375
options = IndicesOptions.fromOptions(false, true, true, false, false);
357376
context = new IndexNameExpressionResolver.Context(state, options, false);

0 commit comments

Comments
 (0)