Pulkit
Pulkit

Reputation: 73

Elasticsearch Node IP address and other details using java rest high level client

How can we get node details for elasticseacrh using java high level rest client. We can get node details in KIbana using GET /_cat/nodes . I want to how to get same details using high level rest client , i need IP address of nodes and wether its master node or not.

Upvotes: 0

Views: 792

Answers (1)

Amit
Amit

Reputation: 32386

Looks like JHLRC doesn't have a API to get _cat/nodes API, but it can be easily obtained using the low-level client which is available within JHLRC as shown in below code

private void getNodesAPI(RestHighLevelClient restHighLevelClient) throws IOException {
        RestClient lowLevelClient = restHighLevelClient.getLowLevelClient();
        Request request = new Request(
                "GET",
                "/_cat/nodes?v");
        Response response = lowLevelClient.performRequest(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            System.out.println("resp: \n"+ EntityUtils.toString(response.getEntity()));
        }
    }

Ran above code locally and it works and below is the O/P on console

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           48          99  21    2.59    1.93     1.92 *    opster

Upvotes: 1

Related Questions