3

I'm trying to connect my java client to an elasticsearch server.

Elasticsearch 2.4.0 is installed on a distant server. To access to it, I have to use port 10700. (When I run "telnet xxxx 10700", it worked, so the port is open)

I have an error for 2 days now and I read it could be a conflict between netty4 dependencies, but I'm not able to fix it. (My netty dependencies are transitives, I don't import them by myself)

How can I resolve this problem?

The java code:

public void connexionToEs() throws UnknownHostException {
    String clusterName = "xxxx";
    String serverAddress = "xxxx";

    try{
        Settings settings = Settings.builder()
                .put("cluster.name", clusterName)
                .put("client.transport.sniff", true)
                .build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(serverAddress), 10700));

        SearchResponse response = client.prepareSearch().execute().actionGet();
        String output = response.toString();
        System.out.println(output);
        client.close();
    }catch(Exception e){
        e.printStackTrace();
    }
}

The dependencies:

<!-- DEPENDENCIES FOR ELASTICSEARCH CLIENT -->
<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch</artifactId>
  <version>5.2.0</version>
</dependency>

<dependency>
  <groupId>org.elasticsearch.client</groupId>
  <artifactId>transport</artifactId>
  <version>5.2.0</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>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-web</artifactId>
  <version>2.6.2</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-to-slf4j</artifactId>
  <version>2.6.2</version>
</dependency>

The error:

Exception in thread "elasticsearch[_client_][management][T#1]" java.lang.NoSuchMethodError: io.netty.buffer.CompositeByteBuf.addComponents(ZLjava/lang/Iterable;)Lio/netty/buffer/CompositeByteBuf;
at org.elasticsearch.transport.netty4.Netty4Utils.toByteBuf(Netty4Utils.java:78)
at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:422)
at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:93)
at org.elasticsearch.transport.TcpTransport.internalSendMessage(TcpTransport.java:1058)
at org.elasticsearch.transport.TcpTransport.sendRequestToChannel(TcpTransport.java:1040)
at org.elasticsearch.transport.TcpTransport.executeHandshake(TcpTransport.java:1555)
at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:502)
at org.elasticsearch.transport.TcpTransport.connectToNode(TcpTransport.java:460)
at org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:318)
at org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1.run(TransportClientNodesService.java:488)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:527)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

The netty4 dependencies:

io.netty:netty:3.10.6.Final
io.netty:netty-buffer:4.0.28.Final
io.netty:netty-codec:4.0.28.Final
io.netty:netty-codec-http:4.1.7.Final
io.netty:netty-common:4.0.28.Final
io.netty:netty-handler:4.0.28.Final
io.netty:netty-resolver:4.1.7.Final
io.netty:netty-transport:4.0.28.Final
4
  • <version>5.2.0</version>...? You aren't running Elasticsearch 5.x Commented Mar 13, 2017 at 13:46
  • Thanks for your answer. I tried with 2.4.0 version before, but it doesn't work ... Commented Mar 13, 2017 at 13:54
  • Maybe it didn't work because your Netty versions are all over the place? You shouldn't expect 4.x code to work on 3.x base Commented Mar 13, 2017 at 13:59
  • I tried to put every netty dependencies in the same version. It doesn't work Commented Mar 13, 2017 at 14:12

5 Answers 5

2

I solved a similar problem, with as following:

<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-client</artifactId>
    <version>1.3.0</version>
    <exclusions>
        <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

1

Please try using the matching Java dependency for your Elasticsearch server

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

4 Comments

Thanks for your answer. I tried this before, but the 2.4.0 elasticsearch-client version doesn't exists...
Yes it does. I copied from here. mvnrepository.com/artifact/org.elasticsearch
Oh, okay, then that is probably only a 5.x feature.
1

Use the right Elasticsearch dependency version - the same as on your server.

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

Also, 2.x doesn't require the elasticsearch transport dependency. You can remove

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

Finally, 2.x does not use the PreBuiltTransportClient. See the documentation here.

Comments

0

The error is at the top of the stacktrace: Exception in thread "elasticsearch[client][management][T#1]" java.lang.NoSuchMethodError: io.netty.buffer.CompositeByteBuf.addComponents(ZLjava/lang/Iterable;)Lio/netty/buffer/CompositeByteBuf;

Your code is calling the addComponents(...) method of the io.netty.buffer.ComposityByteBuff class, but at runtime this method is not available.

Very likely this is due to a different compilation and runtime environment. The versions of the libraries you use to compile your source and the versions of the libraries that are used at runtime are probably not the same.

1 Comment

Thanks for your answer, I'll try to change that.
0

Exclude these netty-all dependency. This will fix your issue.

compile.exclude group: "io.netty", module:"netty-all"
compile.exclude group: "org.jboss.netty", module:"netty"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.