Elasticsearch server cannot connect with java api

Hi,
J have a spring boot application , I have in elasticsaerch connect in localhost:9200 but i need to connect the spring boot application to elasticsearch server with the transport client but spring boot application connect to node client and not connect to server.
This is my Elasticsearch Configuration:

public class EsConfig {

    @Value("${spring.data.elasticsearch.properties..host}")
    private String EsHost;

    @Value("${spring.data.elasticsearch.properties.port}")
    private int EsPort;

    @Value("${spring.data.elasticsearch.properties.clustername}")
    private String EsClusterName;

    @Bean
    public Client client() {

    	try{
    		Settings esSettings = Settings.builder()
            		.put("cluster.name", "mkyong-cluster").build();
            
            TransportClient client = new PreBuiltTransportClient(esSettings).addTransportAddress(
    				  new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));
            return client;
    	}catch(Exception e){
   		e.printStackTrace();
    		System.out.println(e.getMessage());
    	}
		return null;
        
        return TransportClient.builder()
               .settings(esSettings)
                .build()
               .addTransportAddress(
				  new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort));
   }

    
    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }
}

This is my application.properties:
spring.data.elasticsearch.properties.path.home=target/elastic-embedded
spring.data.elasticsearch.properties.transport.tcp.connect_timeout=60s
spring.data.elasticsearch.properties.clustername = mkyong-cluster
spring.data.elasticsearch.properties.host = localhost
spring.data.elasticsearch.properties.port = 9300

This is my response in console:

client.type = node
cluster.name = elasticsearch
clustername = mkyong-cluster
host = localhost
http.enabled = false
name = Mondo
node.local = true
path.home = target/elastic-embedded
path.logs = C:/Project/workspace/workspace1/backend-project/target/elastic-embedded/logs
port = 9300
transport.tcp.connect_timeout = 60s

I need to connect in elasticsearch server but does not exist in localhost:9200 but he connect to node local and client type node not transport
Can help please.

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