Skip to content

Commit

Permalink
Improve error messages for _stats with closed indices (#13012) (#13338
Browse files Browse the repository at this point in the history
)
  • Loading branch information
srikanthpadakanti committed Apr 23, 2024
1 parent fd89920 commit 3956365
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
- Enabled mockTelemetryPlugin for IT and fixed OOM issues ([#13054](https://github.com/opensearch-project/OpenSearch/pull/13054))
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
- Fix snapshot _status API to return correct status for partial snapshots ([#13260](https://github.com/opensearch-project/OpenSearch/pull/13260))
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
- Improve the error messages for _stats with closed indices ([#13012](https://github.com/opensearch-project/OpenSearch/pull/13012))
- Ignore BaseRestHandler unconsumed content check as it's always consumed. ([#13290](https://github.com/opensearch-project/OpenSearch/pull/13290))

### Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void testIndicesOptions() {
request.indicesOptions(IndicesOptions.fromParameters("closed", null, null, "false", SearchRequest.DEFAULT_INDICES_OPTIONS));
response = client().execute(RankEvalAction.INSTANCE, request).actionGet();
assertEquals(1, response.getFailures().size());
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IndexClosedException.class));
assertThat(response.getFailures().get("amsterdam_query"), instanceOf(IllegalArgumentException.class));

// test allow_no_indices
request = new RankEvalRequest(task, new String[] { "bad*" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,13 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set<Inde
private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, IndexMetadata index) {
if (index.getState() == IndexMetadata.State.CLOSE) {
if (options.forbidClosedIndices() && options.ignoreUnavailable() == false) {
throw new IndexClosedException(index.getIndex());
if (options.expandWildcardsClosed() == true && options.getExpandWildcards().size() == 1) {
throw new IllegalArgumentException(
"To expand [" + index.getState() + "] wildcard, please set forbid_closed_indices to `false`"
);
} else {
throw new IndexClosedException(index.getIndex());
}
} else {
return options.forbidClosedIndices() == false && addIndex(index, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ public void testIndexOptionsWildcardExpansion() {
assertEquals(1, results.length);
assertThat(results, arrayContainingInAnyOrder(".hidden-closed"));

options = IndicesOptions.fromOptions(false, true, false, true, false, false, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);

results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);

try {
options = IndicesOptions.fromOptions(false, true, false, true, false, true, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);

results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
} catch (IllegalArgumentException iae) {
String expectedMessage = "To expand [CLOSE] wildcard, please set forbid_closed_indices to `false`";
assertEquals(expectedMessage, iae.getMessage());
}

// Only open
options = IndicesOptions.fromOptions(false, true, true, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);
Expand Down

0 comments on commit 3956365

Please sign in to comment.