3030import org .elasticsearch .action .support .IndicesOptions ;
3131import org .elasticsearch .client .Client ;
3232import org .elasticsearch .client .Requests ;
33+ import org .elasticsearch .cluster .metadata .IndexMetaData ;
34+ import org .elasticsearch .cluster .metadata .MetaData ;
3335import org .elasticsearch .common .Strings ;
3436import org .elasticsearch .common .Table ;
3537import org .elasticsearch .common .inject .Inject ;
@@ -69,8 +71,9 @@ public void doRequest(final RestRequest request, final RestChannel channel, fina
6971 client .admin ().cluster ().state (clusterStateRequest , new RestActionListener <ClusterStateResponse >(channel ) {
7072 @ Override
7173 public void processResponse (final ClusterStateResponse clusterStateResponse ) {
72- final String [] concreteIndices = clusterStateResponse .getState ().metaData ().concreteIndices (IndicesOptions .lenientExpandOpen (), indices );
73- ClusterHealthRequest clusterHealthRequest = Requests .clusterHealthRequest (concreteIndices );
74+ final String [] concreteIndices = clusterStateResponse .getState ().metaData ().concreteIndices (IndicesOptions .fromOptions (false , true , true , true ), indices );
75+ final String [] openIndices = clusterStateResponse .getState ().metaData ().concreteIndices (IndicesOptions .lenientExpandOpen (), indices );
76+ ClusterHealthRequest clusterHealthRequest = Requests .clusterHealthRequest (openIndices );
7477 clusterHealthRequest .local (request .paramAsBoolean ("local" , clusterHealthRequest .local ()));
7578 client .admin ().cluster ().health (clusterHealthRequest , new RestActionListener <ClusterHealthResponse >(channel ) {
7679 @ Override
@@ -80,7 +83,7 @@ public void processResponse(final ClusterHealthResponse clusterHealthResponse) {
8083 client .admin ().indices ().stats (indicesStatsRequest , new RestResponseListener <IndicesStatsResponse >(channel ) {
8184 @ Override
8285 public RestResponse buildResponse (IndicesStatsResponse indicesStatsResponse ) throws Exception {
83- Table tab = buildTable (request , concreteIndices , clusterHealthResponse , indicesStatsResponse );
86+ Table tab = buildTable (request , concreteIndices , clusterHealthResponse , indicesStatsResponse , clusterStateResponse . getState (). metaData () );
8487 return RestTable .buildResponse (tab , channel );
8588 }
8689 });
@@ -96,6 +99,7 @@ Table getTableWithHeader(final RestRequest request) {
9699 Table table = new Table ();
97100 table .startHeaders ();
98101 table .addCell ("health" , "alias:h;desc:current health status" );
102+ table .addCell ("status" , "alias:s;desc:open/close status" );
99103 table .addCell ("index" , "alias:i,idx;desc:index name" );
100104 table .addCell ("pri" , "alias:p,shards.primary,shardsPrimary;text-align:right;desc:number of primary shards" );
101105 table .addCell ("rep" , "alias:r,shards.replica,shardsReplica;text-align:right;desc:number of replica shards" );
@@ -284,15 +288,18 @@ Table getTableWithHeader(final RestRequest request) {
284288 return table ;
285289 }
286290
287- private Table buildTable (RestRequest request , String [] indices , ClusterHealthResponse health , IndicesStatsResponse stats ) {
291+ private Table buildTable (RestRequest request , String [] indices , ClusterHealthResponse health , IndicesStatsResponse stats , MetaData indexMetaDatas ) {
288292 Table table = getTableWithHeader (request );
289293
290294 for (String index : indices ) {
291295 ClusterIndexHealth indexHealth = health .getIndices ().get (index );
292296 IndexStats indexStats = stats .getIndices ().get (index );
297+ IndexMetaData indexMetaData = indexMetaDatas .getIndices ().get (index );
298+ IndexMetaData .State state = indexMetaData .getState ();
293299
294300 table .startRow ();
295- table .addCell (indexHealth == null ? "red*" : indexHealth .getStatus ().toString ().toLowerCase (Locale .getDefault ()));
301+ table .addCell (state == IndexMetaData .State .OPEN ? (indexHealth == null ? "red*" : indexHealth .getStatus ().toString ().toLowerCase (Locale .ROOT )) : null );
302+ table .addCell (state .toString ().toLowerCase (Locale .ROOT ));
296303 table .addCell (index );
297304 table .addCell (indexHealth == null ? null : indexHealth .getNumberOfShards ());
298305 table .addCell (indexHealth == null ? null : indexHealth .getNumberOfReplicas ());
0 commit comments