Browse Source

add version and master_node flags to cluster state

Shay Banon 11 years ago
parent
commit
e5f43a1867

+ 7 - 1
docs/reference/cluster/state.asciidoc

@@ -27,10 +27,16 @@ $ curl -XGET 'http://localhost:9200/_cluster/state/{metrics}/{indices}'
 
 `metrics` can be a comma-separated list of
 
+`version`::
+    Shows the cluster state version.
+
+`master_node`::
+    Shows the elected `master_node` part of the response
+
 `nodes`::
     Shows the `nodes` part of the response
 
-`routing_table`:: 
+`routing_table`::
     Shows the `routing_table` part of the response. If you supply a comma separated list of indices, the returned output will only contain the indices listed.
 
 `metadata`::

+ 5 - 1
src/main/java/org/elasticsearch/cluster/ClusterState.java

@@ -235,7 +235,11 @@ public class ClusterState implements ToXContent {
         Set<String> metrics = Strings.splitStringByCommaToSet(params.param("metric", "_all"));
         boolean isAllMetricsOnly = metrics.size() == 1 && metrics.contains("_all");
 
-        if (isAllMetricsOnly || metrics.contains("nodes")) {
+        if (isAllMetricsOnly || metrics.contains("version")) {
+            builder.field("version", version);
+        }
+
+        if (isAllMetricsOnly || metrics.contains("master_node")) {
             builder.field("master_node", nodes().masterNodeId());
         }
 

+ 1 - 1
src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java

@@ -71,7 +71,7 @@ public class RestClusterStateAction extends BaseRestHandler {
         Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));
         boolean isAllMetricsOnly = metrics.size() == 1 && metrics.contains("_all");
         if (!isAllMetricsOnly) {
-            clusterStateRequest.nodes(metrics.contains("nodes"));
+            clusterStateRequest.nodes(metrics.contains("nodes") || metrics.contains("master_node"));
             clusterStateRequest.routingTable(metrics.contains("routing_table"));
             clusterStateRequest.metaData(metrics.contains("metadata"));
             clusterStateRequest.blocks(metrics.contains("blocks"));