# Elasticsearch server cannot connect with java api

**URL:** <https://discuss.elastic.co/t/elasticsearch-server-cannot-connect-with-java-api/83374>\
**Category:** Elasticsearch\
**Created:** [April 24, 2017, 8:13am UTC](https://discuss.elastic.co/t/elasticsearch-server-cannot-connect-with-java-api/83374 "2017-04-24T08:13:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zegdene](https://avatars.discourse-cdn.com/v4/letter/z/76d3ee/32.png) [@zegdene](https://discuss.elastic.co/u/zegdene)\
**Post date:** [April 24, 2017, 8:13am UTC](https://discuss.elastic.co/t/elasticsearch-server-cannot-connect-with-java-api/83374/1 "2017-04-24T08:13:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 22, 2017, 8:27am UTC](https://discuss.elastic.co/t/elasticsearch-server-cannot-connect-with-java-api/83374/2 "2017-05-22T08:27:33Z")

</div>

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