Cluster Health API
editCluster Health API
editThe Cluster Health API allows getting cluster health.
Cluster Health Request
editA ClusterHealthRequest
:
ClusterHealthRequest request = new ClusterHealthRequest();
There are no required parameters. By default, the client will check all indices and will not wait for any events.
Indices
editIndices which should be checked can be passed in the constructor:
ClusterHealthRequest request = new ClusterHealthRequest("index1", "index2");
Or using the corresponding setter method:
ClusterHealthRequest request = new ClusterHealthRequest(); request.indices("index1", "index2");
Other parameters
editOther parameters can be passed only through setter methods:
The status to wait (e.g. |
|
Using predefined method |
Wait for |
|
Using |
|
Using |
Synchronous Execution
editClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
Asynchronous Execution
editThe asynchronous execution of a cluster health request requires both the
ClusterHealthRequest
instance and an ActionListener
instance to be
passed to the asynchronous method:
The asynchronous method does not block and returns immediately. Once it is
completed the ActionListener
is called back using the onResponse
method
if the execution successfully completed or using the onFailure
method if
it failed.
A typical listener for ClusterHealthResponse
looks like:
Cluster Health Response
editThe returned ClusterHealthResponse
contains the next information about the
cluster:
Whether request was timed out while processing |
|
Status of the request ( |
int numberOfNodes = response.getNumberOfNodes(); int numberOfDataNodes = response.getNumberOfDataNodes();
int activeShards = response.getActiveShards(); int activePrimaryShards = response.getActivePrimaryShards(); int relocatingShards = response.getRelocatingShards(); int initializingShards = response.getInitializingShards(); int unassignedShards = response.getUnassignedShards(); int delayedUnassignedShards = response.getDelayedUnassignedShards(); double activeShardsPercent = response.getActiveShardsPercent();
Number of active shards |
|
Number of primary active shards |
|
Number of relocating shards |
|
Number of initializing shards |
|
Number of unassigned shards |
|
Number of unassigned shards that are currently being delayed |
|
Percent of active shards |
TimeValue taskMaxWaitingTime = response.getTaskMaxWaitingTime(); int numberOfPendingTasks = response.getNumberOfPendingTasks(); int numberOfInFlightFetch = response.getNumberOfInFlightFetch();
Maximum wait time of all tasks in the queue |
|
Number of currently pending tasks |
|
Number of async fetches that are currently ongoing |
ClusterIndexHealth index = indices.get("index"); ClusterHealthStatus indexStatus = index.getStatus(); int numberOfShards = index.getNumberOfShards(); int numberOfReplicas = index.getNumberOfReplicas(); int activeShards = index.getActiveShards(); int activePrimaryShards = index.getActivePrimaryShards(); int initializingShards = index.getInitializingShards(); int relocatingShards = index.getRelocatingShards(); int unassignedShards = index.getUnassignedShards();
Map<Integer, ClusterShardHealth> shards = index.getShards(); ClusterShardHealth shardHealth = shards.get(0); int shardId = shardHealth.getShardId(); ClusterHealthStatus shardStatus = shardHealth.getStatus(); int active = shardHealth.getActiveShards(); int initializing = shardHealth.getInitializingShards(); int unassigned = shardHealth.getUnassignedShards(); int relocating = shardHealth.getRelocatingShards(); boolean primaryActive = shardHealth.isPrimaryActive();