Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError

I am looking forward to integrating Elasticsearch in the 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 run the project, I get the following error, and I do not know why:

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

Did I forget to add the addiction?

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

I hope you help me

+5
source share
3 answers

I just stumbled upon the same problem. Elasticsearch docs seem to be incomplete. In addition to the client transport dependency, you also need to add the elasticsearch dependency:

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

You will also need the log4j dependency, but this is clearly stated in the Elasticsearch docs .

+12
source

for me it looks like elastic search has the wrong version of dependency in 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 replacing version 5.1.1 well, it looks like it also needs log4j ?!

Best regards, noirabys

+2
source

As noted in this issue on Elasticsearch Github pages, SpringBoot Starter manages some of the default dependencies that determine the default version of ElasticSearch below 5.1. 1, so there is no such class.

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

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

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1261055/


All Articles