diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml index 4da58c2ed4d..5ad29d9fdec 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml @@ -273,3 +273,19 @@ open \s+ foo\n open \s+ baz\n $/ + +--- +"Test cat indices with invalid health parameter": + + - do: + indices.create: + index: foo + body: + settings: + number_of_shards: "1" + number_of_replicas: "0" + + - do: + catch: bad_request + cat.indices: + health: "invalid-health-value" diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 9ddedb5340a..69c16876b97 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -216,21 +216,27 @@ public class RestIndicesAction extends AbstractCatAction { return new GroupedActionListener<>(new ActionListener>() { @Override public void onResponse(final Collection responses) { - GetSettingsResponse settingsResponse = extractResponse(responses, GetSettingsResponse.class); - Map indicesSettings = StreamSupport.stream(settingsResponse.getIndexToSettings().spliterator(), false) - .collect(Collectors.toMap(cursor -> cursor.key, cursor -> cursor.value)); + try { + GetSettingsResponse settingsResponse = extractResponse(responses, GetSettingsResponse.class); + Map indicesSettings = StreamSupport.stream(settingsResponse.getIndexToSettings().spliterator(), false) + .collect(Collectors.toMap(cursor -> cursor.key, cursor -> cursor.value)); - ClusterStateResponse stateResponse = extractResponse(responses, ClusterStateResponse.class); - Map indicesStates = StreamSupport.stream(stateResponse.getState().getMetadata().spliterator(), false) - .collect(Collectors.toMap(indexMetadata -> indexMetadata.getIndex().getName(), Function.identity())); + ClusterStateResponse stateResponse = extractResponse(responses, ClusterStateResponse.class); + Map indicesStates = + StreamSupport.stream(stateResponse.getState().getMetadata().spliterator(), false) + .collect(Collectors.toMap(indexMetadata -> indexMetadata.getIndex().getName(), Function.identity())); - ClusterHealthResponse healthResponse = extractResponse(responses, ClusterHealthResponse.class); - Map indicesHealths = healthResponse.getIndices(); + ClusterHealthResponse healthResponse = extractResponse(responses, ClusterHealthResponse.class); + Map indicesHealths = healthResponse.getIndices(); - IndicesStatsResponse statsResponse = extractResponse(responses, IndicesStatsResponse.class); - Map indicesStats = statsResponse.getIndices(); + IndicesStatsResponse statsResponse = extractResponse(responses, IndicesStatsResponse.class); + Map indicesStats = statsResponse.getIndices(); - listener.onResponse(buildTable(request, indicesSettings, indicesHealths, indicesStats, indicesStates)); + Table responseTable = buildTable(request, indicesSettings, indicesHealths, indicesStats, indicesStates); + listener.onResponse(responseTable); + } catch (Exception e) { + onFailure(e); + } } @Override