Null pointer exception in GetRequest for index

Hello ,
i am trying to get index from ES using java ,
below is the code which i have used, but i am getting null values to getrequest obj ,then its throwing null pointer exception

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(
new HttpHost(eshost, esport)));

GetRequest getRequest = new GetRequest("jsonvalidation"); // jsonvalidation is my index name

please help me with correct code to retrive the index

Thanks for help inadvance..!!

Hi @vinay123,

when do you get the NPE (after which command, I don't think constructing the builders and the client will trigger it?) and how does it look like? Can you please attach a Stacktrace?

I don't exactly know what you want to do as I don't know which API you are calling.

If you want to do a GET document call, you are missing the document id. see

GetRequest getRequest = new GetRequest("jsonvalidation", "1");
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);

If you want to do a GET index call, see

GetIndexRequest request = new GetIndexRequest("jsonvalidation");
GetIndexResponse getIndexResponse = client.indices().get(request, RequestOptions.DEFAULT);

I am trying to get index, i have used same methods which you have specified, but i am getting error, unable to consider the arguments ,.

Which version are you using?

6.5 version

It's probably not supported.
6.8 client might have this.

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