Error while using Java High Level Rest Client


(Navneet Singh) #1

Hi,
I am trying to develop a spring boot based elasticsearch project and I am trying to use Java High Level Rest Client in the same.
I am initializing the client like this:

RestHighLevelClient client = new RestHighLevelClient(
				RestClient.builder(
                                    new HttpHost("localhost", 9200, "http"), 
                                    new HttpHost("localhost", 9201, "http"))
                                  );

But I am encountering an exception caused by:

Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_151]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]
	... 54 common frames omitted

My pom.xml has the following dependencies:

        <dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>6.2.2</version>
		</dependency>
        <dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>6.2.2</version>
		</dependency>

I have also tried adding

	<repositories>
		<repository>
			<id>elastic-lucene-snapshots</id>
			<name>Elastic Lucene Snapshots</name>
			<url>http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

as mentioned in the documentation but the exception is still there.
I have also checked the mvn dependency:tree and lucene-core and other dependencies are there.
Please help me out.


(David Pilato) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

Please update your post and remove all the bold (**) you tried to add.


(Navneet Singh) #3

Hi David,
I have updated the query as suggested by you.
Thanks for the input.


(David Pilato) #4

Much better. Thanks!

Can you share the full dependency:tree ?


(Navneet Singh) #5

mvn dependency tree

+- org.elasticsearch:elasticsearch:jar:6.2.2:compile
 |  +- org.elasticsearch:elasticsearch-core:jar:6.2.2:compile
 |  +- org.apache.lucene:lucene-core:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-analyzers-common:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-backward-codecs:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-grouping:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-highlighter:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-join:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-memory:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-misc:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-queries:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-queryparser:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-sandbox:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-spatial:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-spatial-extras:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-spatial3d:jar:7.2.1:compile
 |  +- org.apache.lucene:lucene-suggest:jar:7.2.1:compile
 |  +- org.elasticsearch:securesm:jar:1.2:compile
 |  +- org.elasticsearch:elasticsearch-cli:jar:6.2.2:compile
 |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
 |  +- com.carrotsearch:hppc:jar:0.7.1:compile
 |  +- joda-time:joda-time:jar:2.9.9:compile
 |  +- org.yaml:snakeyaml:jar:1.19:compile
 |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.4:compile
 |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.9.4:compile
 |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.9.4:compile
 |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.9.4:compile
 |  +- com.tdunning:t-digest:jar:3.0:compile
 |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
 |  +- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
 |  \- org.elasticsearch:jna:jar:4.5.1:compile
 +- org.springframework.boot:spring-boot-starter-web:jar:2.0.0.RELEASE:compile
 |  +- org.springframework.boot:spring-boot-starter:jar:2.0.0.RELEASE:compile
 |  |  +- org.springframework.boot:spring-boot:jar:2.0.0.RELEASE:compile
 |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.0.RELEASE:compile
 |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.0.RELEASE:compile
 |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
 |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
 |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
 |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
 |  |  \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
 |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.0.RELEASE:compile
 |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.4:compile
 |  |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
 |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.4:compile
 |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.4:compile
 |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.4:compile
 |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.0.RELEASE:compile
 |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.28:compile
 |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.28:compile
 |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.28:compile
 |  +- org.hibernate.validator:hibernate-validator:jar:6.0.7.Final:compile
 |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
 |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
 |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
 |  +- org.springframework:spring-web:jar:5.0.4.RELEASE:compile
 |  |  \- org.springframework:spring-beans:jar:5.0.4.RELEASE:compile
 |  \- org.springframework:spring-webmvc:jar:5.0.4.RELEASE:compile
 |     +- org.springframework:spring-aop:jar:5.0.4.RELEASE:compile
 |     +- org.springframework:spring-context:jar:5.0.4.RELEASE:compile
 |     \- org.springframework:spring-expression:jar:5.0.4.RELEASE:compile
 +- org.springframework.boot:spring-boot-starter-test:jar:2.0.0.RELEASE:test
 |  +- org.springframework.boot:spring-boot-test:jar:2.0.0.RELEASE:test
 |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.0.RELEASE:test
 |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
 |  |  +- net.minidev:json-smart:jar:2.3:test
 |  |  |  \- net.minidev:accessors-smart:jar:1.2:test
 |  |  |     \- org.ow2.asm:asm:jar:5.0.4:test
 |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
 |  +- junit:junit:jar:4.12:test
 |  +- org.assertj:assertj-core:jar:3.9.1:test
 |  +- org.mockito:mockito-core:jar:2.15.0:test
 |  |  +- net.bytebuddy:byte-buddy:jar:1.7.10:test
 |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.10:test
 |  |  \- org.objenesis:objenesis:jar:2.6:test
 |  +- org.hamcrest:hamcrest-core:jar:1.3:test
 |  +- org.hamcrest:hamcrest-library:jar:1.3:test
 |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
 |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
 |  +- org.springframework:spring-core:jar:5.0.4.RELEASE:compile
 |  |  \- org.springframework:spring-jcl:jar:5.0.4.RELEASE:compile
 |  +- org.springframework:spring-test:jar:5.0.4.RELEASE:test
 |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
 +- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.0.RELEASE:compile
 |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.0.0.RELEASE:compile
 |  |  \- org.springframework.boot:spring-boot-actuator:jar:2.0.0.RELEASE:compile
 |  \- io.micrometer:micrometer-core:jar:1.0.1:compile
 |     \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
 \- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:6.2.2:compile
    +- org.elasticsearch.client:elasticsearch-rest-client:jar:6.2.2:compile
    |  +- org.apache.httpcomponents:httpclient:jar:4.5.5:compile
    |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:compile
    |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.3:compile
    |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.9:compile
    |  +- commons-codec:commons-codec:jar:1.11:compile
    |  \- commons-logging:commons-logging:jar:1.1.3:compile
    +- org.elasticsearch.plugin:parent-join-client:jar:6.2.2:compile
    |  +- org.locationtech.spatial4j:spatial4j:jar:0.6:compile
    |  +- com.vividsolutions:jts:jar:1.13:compile
    |  \- org.apache.logging.log4j:log4j-core:jar:2.10.0:compile
    +- org.elasticsearch.plugin:aggs-matrix-stats-client:jar:6.2.2:compile
    \- org.elasticsearch.plugin:rank-eval-client:jar:6.2.2:compile

(David Pilato) #6

Nothing looks wrong as far as I can tell. May be share a minimalist sample project on github we can look at?

Note: I never tried with Spring boot yet with the High Level client. That's on my TODO list though :slight_smile:


(Navneet Singh) #7

Hi David,
I have pushed a basic version of the project on github.
Please find it here SpringBoot-ES


(Navneet Singh) #8

Well, I solved it.
RCA
Actually, it all started when I included

        <dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>6.2.2</version>
		</dependency>

and it uses elasticsearch:5.6.8 and joda-time:2.9.9. then I started getting following exception

java.lang.ClassNotFoundException: org.joda.time.format.ISODateTimeFormat

To eliminate that I included

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

and then I started getting

Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_151]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]
	... 54 common frames omitted

Actually, the problem was not with Lucene but with joda-time:2.9.9 in the first place.
So, to solve that include

		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
			<version>2.9.4</version>
		</dependency>

and remove

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

from your pom.xml.


(system) closed #9

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