# Unable to connect to Elastic search cloud with Transport client API

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362>\
**Category:** Elasticsearch\
**Created:** [January 23, 2019, 9:14am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362 "2019-01-23T09:14:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 9:14am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/1 "2019-01-23T09:14:41Z")

</div>

Please help me to connect to the elastic cloud from the transport client

pom.xml

```
 <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>6.0.0</version>
    </dependency>

```

Code in JAVA Spring BOOT

```
      boolean enableSsl = true;
    Settings settings = Settings.builder()
            .put("client.transport.nodes_sampler_interval", "5s")
            .put("client.transport.sniff", false)
            .put("transport.tcp.compress", true)
            .put("cluster.name", clusterName)
            .put("xpack.security.transport.ssl.enabled", enableSsl)
            .put("request.headers.X-Found-Cluster", "${cluster.name}")
            .put("xpack.security.user", System.getProperty("xpack.security.user"))
            .put("xpack.security.transport.ssl.verification_mode", insecure ? "none" : "full")
            .build();

    String hostname = "7c12baf8da6b4c1da553c7557a004844.us-east-1.aws.found.io";
    try {

        System.out.println("CONNECT");
        TransportClient myclient = new PreBuiltTransportClient(settings)
                .addTransportAddress(new TransportAddress(InetAddress.getByName(hostname), 9343));

    }catch (Exception e){
        e.printStackTrace();
    }

```

getting the exception

```
java.lang.NullPointerException
at org.elasticsearch.node.InternalSettingsPreparer.replacePromptPlaceholders(InternalSettingsPreparer.java:160)
at org.elasticsearch.node.InternalSettingsPreparer.finalizeSettings(InternalSettingsPreparer.java:153)
at org.elasticsearch.node.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:52)
at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:97)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:125)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:259)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:125)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:111)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:101)
at com.fms.eventurbo.etelastic.service.EventService.<init>(EventService.java:79)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1262)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1164)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2019, 9:26am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/2 "2019-01-23T09:26:41Z")

</div>

What gives

```
GET /
```

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 9:52am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/4 "2019-01-23T09:52:47Z")

</div>

![kibaaa](https://us1.discourse-cdn.com/elastic/original/3X/6/7/677b0893005c79d5248479b3a10c6b69ed4c7a5b.jpeg)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2019, 10:33am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/5 "2019-01-23T10:33:42Z")

</div>

First you need to use the same client version as the server. 6.5.4 and not 6.0.0.

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 10:33am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/6 "2019-01-23T10:33:43Z")

</div>

Getting another exception with the below code changes

```
 boolean enableSsl = true;
    String clusterId = "7c12baf8da6b4c1da553c7557a004844"; // Your cluster ID here

    String region = "us-east-1";
    Settings settings = Settings.builder()
            .put("client.transport.nodes_sampler_interval", "5s")
            .put("client.transport.sniff", false)
            .put("transport.tcp.compress", true)
            .put("cluster.name", clusterName)
            .put("xpack.security.transport.ssl.enabled", enableSsl)
            .put("request.headers.X-Found-Cluster", clusterId)
            .put("xpack.security.user", "elastic:pass")
            .put("xpack.security.transport.ssl.verification_mode", insecure ? "none" : "full")
            .build();
    String hostname = clusterId + "." + region + ".aws.found.io";
    try {

        System.out.println("CONNECT");
        TransportClient myclient = new PreBuiltTransportClient(settings)
                .addTransportAddress(new TransportAddress(InetAddress.getByName(hostname), 9343));

    }catch (Exception e){
        e.printStackTrace();
    }

```

exception

```
java.lang.IllegalArgumentException: unknown setting [xpack.security.transport.ssl.enabled] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:293)
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:256)
at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:135)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:137)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:259)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:125)

```

Kindly Help @dadoonet

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 10:35am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/7 "2019-01-23T10:35:54Z")

</div>

@dadoonet. Thank you, I will update the same but it was working fine with the local elastic server

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2019, 10:36am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/8 "2019-01-23T10:36:18Z")

</div>

Then you need to read: [https://www.elastic.co/guide/en/elasticsearch/reference/6.5/setup-xpack-client.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/setup-xpack-client.html)

[https://www.elastic.co/guide/en/elastic-stack-overview/6.5/java-clients.html](https://www.elastic.co/guide/en/elastic-stack-overview/6.5/java-clients.html)

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 10:47am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/9 "2019-01-23T10:47:16Z")

</div>

That is already added to the pom.xml file 😥 The version is correct or not please

```
	<dependency>
		<groupId>org.elasticsearch.client</groupId>
		<artifactId>x-pack-transport</artifactId>
		<version>6.5.4</version>
	</dependency>

```

error

```
java.lang.IllegalArgumentException: unknown setting [xpack.security.transport.ssl.enabled] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:476)
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:421)
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:392)
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:363)
at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:148)
```

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 23, 2019, 11:02am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/10 "2019-01-23T11:02:46Z")

</div>

@dadoonet I could see the below item in the documentation

Kindly have a look and guide me to resolve the same

```
 java.lang.IllegalArgumentException: empty text

```

The exception is typically seen when a https request is made to a node that is not using https. If https is desired, please ensure the following setting is in elasticsearch.yml:

```
xpack.security.http.ssl.enabled: true

```

[https://www.elastic.co/guide/en/x-pack/5.4/security-troubleshooting.html](https://www.elastic.co/guide/en/x-pack/5.4/security-troubleshooting.html)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2019, 11:09am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/11 "2019-01-23T11:09:53Z")

</div>

Don't read old documentation. [https://www.elastic.co/guide/en/x-pack/5.4/security-troubleshooting.html](https://www.elastic.co/guide/en/x-pack/5.4/security-troubleshooting.html) is for 5.4.

There is an example of a 6.2 version which I hope is still accurate:

> **[elastic/found-shield-example](https://github.com/elastic/found-shield-example)**
>
> Elastic Cloud Shield Transport Example. Contribute to elastic/found-shield-example development by creating an account on GitHub.

But you should NOT be using the transport client anyway but the REST Client instead.

---

<div class="post-metadata">

**Author:** ![Shyju\_M](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shyju\_M](https://discuss.elastic.co/u/Shyju_M)\
**Post date:** [January 24, 2019, 9:51am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/12 "2019-01-24T09:51:06Z")

</div>

Thank you very much I could connect with the below code

```
public class ElasticsearchConfig {

@Value("${elasticsearch.host}")
private String host;

@Value("${elasticsearch.port}")
private int port;

@Value("${elasticsearch.username}")
private String userName;

@Value("${elasticsearch.password}")
private String password;

@Bean(destroyMethod = "close")
public RestHighLevelClient client() {

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(userName, password));

    RestClientBuilder builder = RestClient.builder(new HttpHost(host, port))
            .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));

    RestHighLevelClient client = new RestHighLevelClient(builder);

    return client;

}

```

}

---

<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:** [February 21, 2019, 9:51am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elastic-search-cloud-with-transport-client-api/165362/13 "2019-02-21T09:51:08Z")

</div>

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