Unable to connect to Elasticsearch with X-Pack enabled

(Hitesh Hotchandani) #1


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")

    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>

            <!-- add the elasticsearch repo -->

Any idea what is going wrong?

(Pjanzen) #2

It would help it you share the error message.

(Hitesh Hotchandani) #3

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.

(Pjanzen) #4

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

(Hitesh Hotchandani) #5

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

Here is my code


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")
                    .addTransportAddress(new TransportAddress(InetAddress.getByName(connectionURL), 9300));

        } catch (Exception e) {


(Pjanzen) #6

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..

(Hitesh Hotchandani) #7

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

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!!

(Hitesh Hotchandani) #8


Anyone with any input appreciated here.

(David Pilato) #9

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

(Ranjit ) #10

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.


(David Pilato) #11

I'm not sure to understand.

(system) #12

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