Hello to everyone!
How can I check cluster helth of Elasticsearch 6.1 through Java code (maybe through Java high level rest client)?
In Rest it will be GET _cluster/health
.
info() should give you some information.
From what class in Java Api I can call info()
?
Also, I found such documentation: https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.1/java-admin-indices.html
But, I can't understand from what class an instance client
is in the code IndicesAdminClient indicesAdminClient = client.admin().indices();
I thought it was HighLevelRestClient
. But in HighLevelRestClient
there is no admin()
method.
May you explain this?
You are not looking at the right documentation. This one is for the Transport client. Have a look at info in high level rest client documentation
with such request http://localhost:9200/_cluster/health?pretty
I have response:
{
"cluster_name" : "portal",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 2,
"active_primary_shards" : 7,
"active_shards" : 14,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
And here I can see field "status" : "green"
. With the help of client.info()
I can only get ClusterName, ClusterUuid, NodeName
and Version
.
How I can get "status"
meaning through Java code?
found this one:
Map<String, String> parameters = singletonMap("wait_for_status", "green");
Response response = client.getLowLevelClient().performRequest("GET", "/_cluster/health", parameters);
ClusterHealthStatus healthStatus;
try (InputStream is = response.getEntity().getContent()) {
Map<String, Object> map = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
healthStatus = ClusterHealthStatus.fromString((String) map.get("status"));
}
if (healthStatus == ClusterHealthStatus.GREEN) {
}
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.