elastic search high level rest client code example

Example: elasticsearch api code call using highlevelrestclient

Request request = new Request("GET", "/_cluster/health");
request.addParameter("wait_for_status", "green"); 
Response response = client.getLowLevelClient().performRequest(request); 

ClusterHealthStatus healthStatus;
try (InputStream is = response.getEntity().getContent()) { 
    Map<String, Object> map = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); 
    healthStatus = ClusterHealthStatus.fromStringString) map.get("status"; 
}

if (healthStatus != ClusterHealthStatus.GREEN) {
    
}

Tags:

Java Example