# Unable to connect to Elasticsearch with X-Pack enabled

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023>\
**Category:** Elasticsearch\
**Created:** [June 22, 2018, 12:50pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023 "2018-06-22T12:50:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [June 22, 2018, 12:50pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/1 "2018-06-22T12:50:02Z")

</div>

Hi

I am using Elasticsearch version 6.2.4.  
After enabling xpack security, I am unable to connect my transport client to elasticsearch

```
TransportClient transportClient1 = new PreBuiltXPackTransportClient(
            Settings.builder().put("cluster.name", "Elastic-application")
                    .put("xpack.security.user", "elastic:pass@123")
                    .build());

    ipPortMapping = ExportMiscellaneousUtils.getURLDetails(connectionURL, ExportMiscellaneousUtils.DEFAULT_TCP_PORT_ELASTICSEARCH);
    for (Map.Entry<InetAddress, Integer> ipPortDetails : ipPortMapping.entrySet()) {
        transportClient1.addTransportAddresses(new TransportAddress(ipPortDetails.getKey(), ipPortDetails.getValue()));
    }

```

Following is the dependencies i have added to my maven  
\> \<elasticsearch.version\>6.2.4\</elasticsearch.version\>

> ```
> <repositories>
> <!-- add the elasticsearch repo -->
> <repository>
> <id>elasticsearch-releases</id>
> <url>https://artifacts.elastic.co/maven</url>
> <releases>
> <enabled>true</enabled>
> </releases>
> <snapshots>
> <enabled>false</enabled>
> </snapshots>
> </repository>
> </repositories>
> <dependency>
> <groupId>org.elasticsearch.client</groupId>
> <artifactId>x-pack-transport</artifactId>
> <version>6.0.0-beta2</version>
> </dependency>
> <dependency>
> <groupId>org.elasticsearch</groupId>
> <artifactId>elasticsearch</artifactId>
> <version>${elasticsearch.version}</version>
> </dependency>
> 
> ```

Any idea what is going wrong?

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [June 22, 2018, 2:06pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/2 "2018-06-22T14:06:05Z")

</div>

It would help it you share the error message.

---

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [June 22, 2018, 2:18pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/3 "2018-06-22T14:18:32Z")

</div>

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.  
Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.common.settings.Settings$Builder.put([Ljava/lang/Object;)Lorg/elasticsearch/common/settings/Settings$Builder;

This is the message I am getting.

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [June 22, 2018, 2:19pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/4 "2018-06-22T14:19:55Z")

</div>

> [@hitesh-inbetween](#):
>
> Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.common.settings.Settings$Builder.put([Ljava/lang/Object;)Lorg/elasticsearch/common/settings/Settings$Builder;

Your code doesn't compile, you should fix that first..

---

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [June 22, 2018, 2:22pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/5 "2018-06-22T14:22:51Z")

</div>

It compiles just fine...  
This is run time error:

Here is my code

Imports

```
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

```

And the connection code.

```
private void prepareClient(String connectionURL) {
        try {
            TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
                    .put("cluster.name", "myClusterName")
                    .put("xpack.security.user", "transport_client_user:x-pack-test-password")
                    .build())
                    .addTransportAddress(new TransportAddress(InetAddress.getByName(connectionURL), 9300));

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

    }
```

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [June 22, 2018, 2:29pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/6 "2018-06-22T14:29:04Z")

</div>

Still, it calls a method that doesn't exists, java.lang.NoSuchMethodError. If I had to guess I would say something is wrong with Settings.builder() and how that is used. That said my java skills are very rusty, I really need to pick that up again..

---

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [June 22, 2018, 2:32pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/7 "2018-06-22T14:32:21Z")

</div>

Yes that's correct. it is unable to find the put method in Settings$builder().

But as per the documentations, above mentioned way is the way to do it...  
Please ref: [https://www.elastic.co/guide/en/elastic-stack-overview/current/java-clients.html](https://www.elastic.co/guide/en/elastic-stack-overview/current/java-clients.html)

The first example here shows the code above...

I wonder what is wrong with my implementation?  
Is it a incorrect dependency version.. or maybe an incorrect dependency itself!!

---

<div class="post-metadata">

**Author:** ![hitesh-inbetween](https://avatars.discourse-cdn.com/v4/letter/h/51bf81/32.png) [@hitesh-inbetween](https://discuss.elastic.co/u/hitesh-inbetween)\
**Post date:** [July 5, 2018, 9:22am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/8 "2018-07-05T09:22:06Z")

</div>

Hi,

Anyone with any input appreciated here.

---

<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:** [July 5, 2018, 10:13am UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/9 "2018-07-05T10:13:44Z")

</div>

may be use the right version instead of 6.0.0-beta2 of xpack client.

---

<div class="post-metadata">

**Author:** ![ranjitparma](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@ranjitparma](https://discuss.elastic.co/u/ranjitparma)\
**Post date:** [July 19, 2018, 2:31pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/10 "2018-07-19T14:31:44Z")

</div>

Hi David,  
We check with right version but when we add the dependency in .pom file then not creating the .jar file, is there any other way for that.

Thanks

---

<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:** [July 19, 2018, 9:07pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/11 "2018-07-19T21:07:12Z")

</div>

I'm not sure to understand.

---

<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:** [August 16, 2018, 9:07pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-with-x-pack-enabled/137023/12 "2018-08-16T21:07:15Z")

</div>

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