Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError
Asked Answered
A

3

7

I am looking forward to integrate Elasticsearch in a Spring Boot Web Application. Here is my configuration that creates my Transport Client:

@Configuration
public class ElasticsearchConfig {

private TransportClient client;

@Bean
public TransportClient client() throws UnknownHostException{

    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", true)
            .build();

    client = new PreBuiltTransportClient(settings);

    client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

    return client;
}

When I start the Project I get following error and I don't know why:

java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin

Did I forgot to add a dependency?

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.1.1</version>
</dependency>

Hope you can help me

Awaken answered 9/12, 2016 at 14:34 Comment(0)
P
15

I just stumbled over the same problem. Seems that the Elasticsearch docs aren't complete. In addition to the transport client dependency, you need to also add the elasticsearch dependency:

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

You'll also need the log4j dependency, but that is clearly stated in the Elasticsearch docs.

Polariscope answered 17/12, 2016 at 22:36 Comment(1)
Hi I am getting java.lang.NoSuchFieldError: defaultConnectionProfile java.lang.NoSuchFieldError: defaultConnectionProfile at org.elasticsearch.transport.netty4.Netty4Transport.createBootstrap(Netty4Transport.java:207) ...can u suggest something in thisStrobel
V
2

for me it looks like elastic search has a wrong dependency version in the pom

  <properties>
    <log4j.version>2.6.2</log4j.version>
</properties>

<dependencies>


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

  </dependency>

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

    <exclusions>
      <exclusion>
        <artifactId>elasticsearch</artifactId>            
        <groupId>org.elasticsearch</groupId></exclusion>
    </exclusions>
  </dependency>      
   <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
        <version>${log4j.version}</version>
    </dependency>

try to replace the version with 5.1.1 well it looks like it also needs log4j ?!

best regards, noirabys

Velazquez answered 15/12, 2016 at 10:30 Comment(0)
S
2

As stated in this issue on Elasticsearch Github pages, SpringBoot starter manages some default dependencies, which defined the default version of ElasticSearch below 5.1.1, so that there is no such class.

You can explicitly define the property in your own pom to override its definition.

<properties>
    <elasticsearch.version>5.1.1</elasticsearch.version>
</properties>

Hope it helps.

Stopwatch answered 22/1, 2018 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.