How to perform Index Stats API using NodeClient?

Hi,

I am using ES 7.10.2

I have come across Index Stats API in ES documentation. Also in Java Lib there is class available named

I did come across NodeClient, so I am trying to fetch index stats as below :

NodeClient nodeClient = new NodeClient(Settings.EMPTY, new ThreadPool(Settings.EMPTY));
				IndicesStatsRequestBuilder indicesStatsRequestBuilder = nodeClient.admin()
						.indices()
						.prepareStats("indexNameHere");
				IndicesStatsResponse indicesStatsResponse = indicesStatsRequestBuilder.get();
				System.out.println("indicesStatsResponse = " + indicesStatsResponse);

But I am getting NodeClient has not been initialized exception, what I am doing wrong ? or am I missing any steps ?

Any help is much appreciated:)

Hi @Nishikant_Tayade .

If you are not successful with the IndicesStatsRequest you can also do it as follows:

 Request request = new Request("GET", "/index_name/_stats");
 var response = client.getLowLevelClient().performRequest(request);
 System.out.println(EntityUtils.toString(response.getEntity()));
1 Like

@RabBit_BR Thanks for reaching out !! As I can't use lowlevelclient, I did found another way to, using NodeClient actaully, I have updated my question.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.