Skip to content

Commit 98009ed

Browse files
Improve error messages for _stats with closed indices (opensearch-project#13012)
* Improve the error messages for _stats with closed indices Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> * Edit the changelog text Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> * correct the test cases Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> * fix to throw appropriate error message Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> * fix to throw appropriate error message Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> --------- Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com> Signed-off-by: Srikanth Padakanti <srikanth29.9@gmail.com>
1 parent bfbdc9f commit 98009ed

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6060
- Enabled mockTelemetryPlugin for IT and fixed OOM issues ([#13054](https://github.com/opensearch-project/OpenSearch/pull/13054))
6161
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
6262
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
63+
- Improve the error messages for _stats with closed indices ([#13012](https://github.com/opensearch-project/OpenSearch/pull/13012))
6364
- Ignore BaseRestHandler unconsumed content check as it's always consumed. ([#13290](https://github.com/opensearch-project/OpenSearch/pull/13290))
6465

6566
### 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
@@ -380,7 +380,13 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set<Inde
380380
private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, IndexMetadata index) {
381381
if (index.getState() == IndexMetadata.State.CLOSE) {
382382
if (options.forbidClosedIndices() && options.ignoreUnavailable() == false) {
383-
throw new IndexClosedException(index.getIndex());
383+
if (options.expandWildcardsClosed() == true && options.getExpandWildcards().size() == 1) {
384+
throw new IllegalArgumentException(
385+
"To expand [" + index.getState() + "] wildcard, please set forbid_closed_indices to `false`"
386+
);
387+
} else {
388+
throw new IndexClosedException(index.getIndex());
389+
}
384390
} else {
385391
return options.forbidClosedIndices() == false && addIndex(index, context);
386392
}

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)