Skip to content

Commit

Permalink
Improve error messages for _stats with closed indices (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#13012)

* Improve the error messages for _stats with closed indices

Signed-off-by: srikanth padakanti <[email protected]>

* Edit the changelog text

Signed-off-by: srikanth padakanti <[email protected]>

* correct the test cases

Signed-off-by: srikanth padakanti <[email protected]>

* fix to throw appropriate error message

Signed-off-by: srikanth padakanti <[email protected]>

* fix to throw appropriate error message

Signed-off-by: srikanth padakanti <[email protected]>

---------

Signed-off-by: srikanth padakanti <[email protected]>
Signed-off-by: Srikanth Padakanti <[email protected]>
  • Loading branch information
srikanthpadakanti authored Apr 22, 2024
1 parent bfbdc9f commit 98009ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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 ([#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 @@ -380,7 +380,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 98009ed

Please sign in to comment.