1

I am trying to create index using RestHighLevelClient, Client got created successfully but while creating index I am getting error.

 CreateIndexRequest request = new CreateIndexRequest(elasticsearchIndex);
    request.settings(Settings.builder()
            .put("index.number_of_shards", 1)
            .put("index.number_of_replicas", 0)
    );
    org.elasticsearch.client.indices.CreateIndexResponse createIndexResponse = elasticsearchClient.indices().create(request, RequestOptions.DEFAULT);





Exception in thread "main" java.net.ConnectException: Connection refused
        at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:788)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)
        at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)
        at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1439)
        at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1406)
        at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:128)

Please let me know the root cause or any solution.

Thanks

1 Answers1

1

Looks like you Application can't connect to the elasticsearch server, can you check the connection setting provided in JHLRC client configuration(hostname and port) and make sure you have connection to your elasticsearch.

You can check the connection yourself by hitting your elasticsearch hostname and port using rest client like postman etc. Also make sure your Application and elasticsearch server have the network connectivity.

Amit
  • 30,756
  • 6
  • 57
  • 88
  • Thanks for the response. I am able to connect( Create Connection), Issue is coming after I try to create index. – Vishal Yadav Dec 22 '20 at 10:28
  • 1
    @VishalYadav this is strange, are you sure, error message which u provided is for your index creation request?? – Amit Dec 22 '20 at 13:25
  • Thanks Sir, it got resolved, The issue was with port, After changing it issue got resolved. – Vishal Yadav Dec 22 '20 at 16:41