Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError

Timo Ademeit picture Timo Ademeit · Dec 9, 2016 · Viewed 11.7k times · Source

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

Answer

Quagaar picture Quagaar · Dec 17, 2016

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.