Getting the Transport Client address

I am using Elasticsearch version number 6.2.4.

This is the Configuration file that I am using for java

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;


import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
@EnableElasticsearchRepositories
public class Config {



    @Bean
    public Client elasticsearchClient() throws UnknownHostException {
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
        return client;
    }

    @Bean(name = {"elasticsearchOperations", "elasticsearchTemplate"})
    public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
        return new ElasticsearchTemplate(elasticsearchClient());
    }

}

Trying to add data to the elasticsearch repository using POST Mapping, I am getting the following error:

{
    "timestamp": "2020-04-17T06:46:13.929+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "None of the configured nodes are available: [{#transport#-1} 
                                      {HUYVYb8YTXSNaYF_Givu5Q}{127.0.0.1}{127.0.0.1:9300}]",
    "path": "/event/save"
}

The elasticsearch instance provided by me is not running locally, but on a server provided by the company. The possible source of error that I think is that the Transport Client is not running on port 9300 but on some other port so I need to change its configuration file.

Is there any way that I can find out the transport client address or there is any other error.

Welcome!

As you might know, the TransportClient is deprecated and will be removed in version 8.
Please switch to the Rest Client instead. Also upgrade your elasticsearch cluster to the latest 6.8 version or better to 7.6.2.

Can I get the link to any documentation that provides in detail how to set up elasticsearch configuration in java

Sure. https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html

Also you can look at my demo project.

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