Home » Elasticsearch Cluster APIs

Elasticsearch Cluster APIs

by Online Tutorials Library

Elasticsearch Cluster APIs

In Elasticsearch, cluster API fetches the information about a cluster and its node. It also makes further changes in them. With the help of Cluster API, we can perform the 21 operations at the cluster level. We can use this API to manage our clusters. We need to specify node name, address or _local keyword along with the GET method to call this API.

As we said, this is a distributed environment where we have a lot of nodes and this Elasticsearch environment can be multi-node deployment as well. So, in this case, cluster API gives us information with respect to the cluster. Below some essential points of cluster API –

  • Most of the cluster APIs allows specifying which nodes to execute.
  • In APIs, we can identify the nodes either using their internal node name, node id, custom attributes, address, or just receiving _local node request.

For Example

Response

You will get the output same as the below response.

Following are some of the commands, which can execute to get more information about a cluster:

  1. Cluster Health
  2. Cluster State
  3. Cluster Stats
  4. Pending Cluster Tasks
  5. Node Stats
  6. Node hot_thread

Cluster Health

Using this API, we can check the health status of the cluster. The cluster health API helps to fetch the health of the cluster. It returns the cluster status as red, yellow, or green for stop, running, or ready, respectively.

Append the _cluster and health keyword in URL and get the status on the cluster health. Execute the following code and get the response:

Copy Code

Response

You will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Cluster State

This API is used to get information about the cluster state. The state information contains the cluster name, state_uuid, version, master node, metadata, routing table, blocks, and much more.

Append the _cluster and state keyword in URL and get the information about the cluster state. Execute the following code and get the state information:

Copy Code

Response

You will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Cluster Stats

Stats stands for statistics. By using stats keyword, we can retrieve the statistics about cluster. It returns the statistics information about cluster along with shard number, memory usage, store size, roles, OS, number of nodes, and file system.

Append the _cluster and stats keyword in URL and get the information about cluster statistics. Execute the following code and get the statistics information of cluster:

Copy code

Response

You will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Pending Cluster Tasks

The pending cluster tasks API manages all the pending tasks in any cluster. It monitors tasks like create index, allocate or fail shard, and update mapping, etc. To monitor these tasks, append the _cluster and pending_tasks in URL and fetch all the remaining/pending tasks in the cluster. Copy the following code and execute the query:

Copy Code

Response

You will get the output like the below response if there is no pending task in the cluster.

Screenshot

Elasticsearch Cluster APIs

Cluster Reroute

The cluster reroute API is responsible for moving shards from one node to another. It can also allocate any unassigned shards and cancels the allocation of any shard. To successfully execute this query, we require to use the POST request method. Look at the following example below and execute it on your system:

Copy Code

Response

You will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Cluster Update Settings

This API helps to update the setting of a cluster. Use the settings keyword to update cluster settings. Most of the cluster level APIs allow the user to specify the node to execute. There are two types of settings –

  1. Persistent – It applied across the restart.
  2. Transient – Do not survive a full cluster restart.

Execute the following code and get the response:

Copy Code

Response

By executing the above query, you will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Persistent API

We can update settings to be persistent settings. Below is an example of persistent update:

Copy Code

Response

By executing the above query, you will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Transient API

We can update settings to be transient settings. Below is an example of persistent update:

Copy Code

Response

By executing the above query, you will get the output like the below response.

Screenshot

Elasticsearch Cluster APIs

Node Stats

The node stats API helps to retrieve the statistics about the node of the cluster. Node stats and cluster stats are almost same. We can retrieve the statistics for any number of nodes. To retrieve the statistics for a node, append _stats keyword along with _nodes keyword in URL.

Copy the following code and execute the query on your system:

Copy Code

Response

By executing the above query, you will get the output like the below response.

Screenshot

You will get the output same as in the below screenshot.

Elasticsearch Cluster APIs

Node hot_threads

This API is responsible for retrieving information about the current hot threads for each node in a cluster. To retrieve the information for hot thread on each node, append hot_threads keyword along with _nodes keyword in URL and get the respond in response body. GET method is used to send this http request.

Copy the following code and execute the query on your system. It will take a bit of time to execute completely.

Copy Code

Response

By executing the above query, you will get the output like the below response.


You may also like