diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index fccff5bd69fc5..057b1afd8eb1e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -74,27 +74,41 @@ public void doRequest(final RestRequest request, final RestChannel channel, fina clusterStateRequest.clear().indices(indices).metaData(true); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); + final IndicesOptions strictExpandIndicesOptions = IndicesOptions.strictExpand(); + clusterStateRequest.indicesOptions(strictExpandIndicesOptions); client.admin().cluster().state(clusterStateRequest, new RestActionListener(channel) { @Override public void processResponse(final ClusterStateResponse clusterStateResponse) { - ClusterState state = clusterStateResponse.getState(); - final IndicesOptions concreteIndicesOptions = IndicesOptions.fromOptions(false, true, true, true); - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, concreteIndicesOptions, indices); - final String[] openIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), indices); - ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(openIndices); + final ClusterState state = clusterStateResponse.getState(); + final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, strictExpandIndicesOptions, indices); + // concreteIndices should contain exactly the indices in state.metaData() that were selected by clusterStateRequest using + // IndicesOptions.strictExpand(). We select the indices again here so that they can be displayed in the resulting table + // in the requesting order. + assert concreteIndices.length == state.metaData().getIndices().size(); + + // Indices that were successfully resolved during the cluster state request might be deleted when the subsequent cluster + // health and indices stats requests execute. We have to distinguish two cases: + // 1) the deleted index was explicitly passed as parameter to the /_cat/indices request. In this case we want the subsequent + // requests to fail. + // 2) the deleted index was resolved as part of a wildcard or _all. In this case, we want the subsequent requests not to + // fail on the deleted index (as we want to ignore wildcards that cannot be resolved). + // This behavior can be ensured by letting the cluster health and indices stats requests re-resolve the index names with the + // same indices options that we used for the initial cluster state request (strictExpand). Unfortunately cluster health + // requests hard-code their indices options and the best we can do is apply strictExpand to the indices stats request. + ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); client.admin().cluster().health(clusterHealthRequest, new RestActionListener(channel) { @Override public void processResponse(final ClusterHealthResponse clusterHealthResponse) { IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); - indicesStatsRequest.indices(concreteIndices); - indicesStatsRequest.indicesOptions(concreteIndicesOptions); + indicesStatsRequest.indices(indices); + indicesStatsRequest.indicesOptions(strictExpandIndicesOptions); indicesStatsRequest.all(); client.admin().indices().stats(indicesStatsRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception { - Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse, clusterStateResponse.getState().metaData()); + Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse, state.metaData()); return RestTable.buildResponse(tab, channel); } }); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yaml index a5a67d1a557cb..51f8fe9ed4c8d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yaml @@ -24,7 +24,7 @@ - match: $body: | /^(green \s+ - (open|close) \s+ + open \s+ index1 \s+ 1 \s+ 0 \s+ @@ -49,3 +49,24 @@ (\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s* ) $/ + - do: + indices.close: + index: index1 + + - do: + cat.indices: + index: index* + + - match: + $body: | + /^( \s+ + close \s+ + index1 \s+ + \s+ + \s+ + \s+ + \s+ + \s+ + \s* + ) + $/