“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:
The API accepts the following path parameters:
- metrics – this specifies a list of options to fetch from the cluster. This is an optional parameter. Accepted options include
- _all – show all cluster metrics.
- blocks – only show the blocks from the response.
- master_node – fetch only the master node part.
- metadata – display only the metadata.
- nodes – shown only the nodes.
- routing_nodes – show routing nodes.
- routing_table – display the routing_table only.
- version – show cluster version.
- 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:
- local – fetches the cluster information from the local node only.
- expand_wildcards – specifies whether to expand the wildcard expressions.
- 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.
The resulting cluster state information is as shown:
Example 2
The example below shows the routing table metadata for index 6IoKfqY1TredUYfi5DL7PA:
The query will return the metadata and routing table of the specified index as shown:
Example 3
To fetch the cluster version, run:
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:
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.