| by Arround The Web | No comments

Elasticsearch Show Cluster State

“Whether you are just starting with Elasticsearch or a seasoned professional, you will encounter instances where you need to fetch state information about the Elasticsearch cluster.

You can then use the information to determine the cluster health and perform diagnostic or debugging for various issues.

This post will discover how you can fetch the cluster state information with various simple steps.”

Elasticsearch Cluster State API

Elasticsearch utilizes restful API extensively. Therefore, it’s no surprise that it provides an API endpoint for fetching cluster state information.

The endpoint syntax is as shown:

GET /_cluster/state/<metrics>/<target>

 
The API accepts the following path parameters:

    1. metrics – this specifies a list of options to fetch from the cluster. This is an optional parameter. Accepted options include
      1. _all – show all cluster metrics.
      2. blocks ­– only show the blocks from the response.
      3. master_node – fetch only the master node part.
      4. metadata – display only the metadata.
      5. nodes – shown only the nodes.
      6. routing_nodes – show routing nodes.
      7. routing_table – display the routing_table only.
      8. version – show cluster version.
    2. target – specifies a list of data streams, indices, and aliases as comma-separated values. This is an optional parameter.

Other parameters supported in the query include:

    1. local – fetches the cluster information from the local node only.
    2. expand_wildcards – specifies whether to expand the wildcard expressions.
    3. ignore_unavailable – if true, unavailable indices are ignored.

Discover the documentation to pick up more on this API, query parameter, and more.

Example 1

The following example returns all the information about the cluster state.

curl -XGET "http://localhost:9200/_cluster/state/_all?pretty=true" -H "kbn-xsrf: reporting"

 
The resulting cluster state information is as shown:

Example 2

The example below shows the routing table metadata for index 6IoKfqY1TredUYfi5DL7PA:

curl -XGET "http://localhost:9200/_cluster/state/metadata,routing_table/6IoKfqY1TredUYfi5DL7PA" -H "kbn-xsrf: reporting"

 
The query will return the metadata and routing table of the specified index as shown:

Example 3

To fetch the cluster version, run:

curl -XGET "http://localhost:9200/_cluster/state/version?pretty" -H "kbn-xsrf: reporting"

 
The example above will return the cluster version as shown:

{
  "cluster_name": "776a462b8a1942bfb8ba46decf49ca8c",
  "cluster_uuid": "6IoKfqY1TredUYfi5DL7PA",
  "version": 1144,
  "state_uuid": "_efEiXwzTwyaBrezYDJ2sA"
}

 

Example 4

To fetch the cluster state in the local node only, run:

curl -XGET "http://localhost:9200/_cluster/state/_all?local=true" -H "kbn-xsrf: reporting"

 
In this case, the query returns information from the local node instead of the master node.

Output:

Conclusion

In this article, you learned about the cluster state API. This API lets you fetch cluster information from the master or local node.

Thanks for reading.

Share Button

Source: linuxhint.com

Leave a Reply