1
votes

I am able to access the ElasticSearch via http://127.0.0.1:9200, however when trying to connect from the same machine via RestHighLevelClient I get the java.net.ConnectException: Connection refused.

try {
        final BulkResponse response=this.restHighLevelClient.bulk(bulkRequest);
}
catch (final IOException exn) {
        LOG.error("Bulk insert failed", exn);
    
}

The configuration class for Elastic search client is like below.

@Bean
public RestHighLevelClient restClient() {
return new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", "9200", "http")));
}

I have retained the default settings in elastic-search.yml file and debugged to be sure that host and port are correct. Any ideas please?

1
Share the code you used to create restHighLevelClient - Nishant
Edited and included the client config. - Kedarnath
CONNECTION REFUSED is the TCP error you will see when there is no application listening to the selected port. Check to see that you actually have a program running and bound to port 9200. - Matt Clark
What if you pass host value as 127.0.0.1 instead of localhost? - Nishant

1 Answers

0
votes

I had the same issue but my problem was that I was connecting to the wrong host by mistake.