Problem with ES5 TransportClient

Hello,
I'm trying to do the simplest thing- create a TransportClient for ES5.0.
My POM file:

<dependencies>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>5.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.6.2</version>
    </dependency>
</dependencies>

And my Java code looks like this:

public class EsTest {
    private static final Logger logger = LogManager.getLogger("EsTest");
    private static TransportClient client;

    public static void main(String[] args) {
        Settings settings = Settings.builder().put("cluster.name", "myCluster").put("client.transport.sniff", true).build();
        TransportClient client = new PreBuiltTransportClient(settings);
    .
    .
    .
    }
}

Yet right after the line:

TransportClient client = new PreBuiltTransportClient(settings);

I get:

client.injector = Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate org.elasticsearch.common.inject.InjectorImpl.toString().

(Settings.EMPTY has the same effect)

Why is this happening?

Hi,

has your project resolved the transitive dependencies of the transport client correctly. Judging from the pom in maven central, it depends on the main elasticsearch jar. I suspect this is missing somehow in your ides project setup.

Hi and thanks for the quick reply.
I have tried adding this to my POM:

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>5.0.1</version>
</dependency>

Did not help.. :frowning:

I'm not sure where the injector error comes from but I just set up a minimal maven project with only the transport client dependency in eclipse. This already pulls the core dependency as expected. I'm able to connect to a local cluster via TransportClient like this:

public static void main(String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true).build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
        SearchResponse searchResponse = client.prepareSearch("index").execute().get();
        System.out.println(searchResponse);
        client.close();
    }

Since your code snippet is missing some parts and the stack trace is also not complete it is hard to guess what's wrong on your end. Maybe you can provide more information about your setup or try an even more minimal setup to at least get a simple connection going. It should be possible as I just checked myself.

@cosec do you have other Elasticsearch jars on your runtime class path?

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