Migration to rest client ,NoSuchFieldError: Lucene_5_5_4 error

Hi ,

I am migrating to Elastic rest client version 5.6.9

When i try to instantiate RestHighLevelClient, i get this error:

RestHighLevelClient client = new RestHighLevelClient(restlowLevelClient);

Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_5_5_4
at org.elasticsearch.Version.(Version.java:85)
at org.elasticsearch.common.logging.DeprecationLogger.(DeprecationLogger.java:159)
at org.elasticsearch.common.ParseField.(ParseField.java:35)
at org.elasticsearch.client.RestHighLevelClient.lambda$getDefaultNamedXContents$46(RestHighLevelClient.java:580)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1696)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.elasticsearch.client.RestHighLevelClient.getDefaultNamedXContents(RestHighLevelClient.java:581)
at org.elasticsearch.client.RestHighLevelClient.(RestHighLevelClient.java:187)
at org.elasticsearch.client.RestHighLevelClient.(RestHighLevelClient.java:177)
at Test.main(Test.java:140)

I have below dependencies in my pom.xml :\

<org.elasticsearch.version>5.6.9</org.elasticsearch.version>
.....

org.elasticsearch elasticsearch ${org.elasticsearch.version} org.elasticsearch.client elasticsearch-rest-high-level-client ${org.elasticsearch.version} org.elasticsearch.client elasticsearch-rest-client ${org.elasticsearch.version}

What gives:

mvn dependency:tree

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building BoltESApplier dev
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.apple.extra:ojdbc12c:jar:7.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:oracleucp:jar:12.1 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:boltlistener:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:aqapi13:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:BOLTSwitchOver-0.0.1:jar:1.0 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.9:tree (default-cli) @ BoltESApplier ---
[INFO] applier:BoltESApplier:jar:dev
[INFO] +- org.apache.kafka:kafka-clients:jar:0.10.2.1:compile
[INFO] | +- net.jpountz.lz4:lz4:jar:1.3.0:compile
[INFO] | +- org.xerial.snappy:snappy-java:jar:1.1.2.6:compile
[INFO] | - org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] +- org.apache.zookeeper:zookeeper:jar:3.4.10:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] | +- log4j:log4j:jar:1.2.16:compile
[INFO] | +- jline:jline:jar:0.9.94:compile
[INFO] | - io.netty:netty:jar:3.10.5.Final:compile
[INFO] +- org.apache.kafka:kafka_2.10:jar:0.10.2.1:compile
[INFO] | +- net.sf.jopt-simple:jopt-simple:jar:5.0.3:compile
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | +- org.scala-lang:scala-library:jar:2.10.6:compile
[INFO] | - com.101tec:zkclient:jar:0.10:compile
[INFO] +- org.apache.curator:curator-framework:jar:2.9.1:compile
[INFO] | - org.apache.curator:curator-client:jar:2.9.1:compile
[INFO] | - com.google.guava:guava:jar:16.0.1:compile
[INFO] +- org.elasticsearch:elasticsearch:jar:5.6.9:compile
[INFO] | +- org.apache.lucene:lucene-core:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-analyzers-common:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-backward-codecs:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-grouping:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-highlighter:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-join:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-memory:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-misc:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-queries:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-queryparser:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-sandbox:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-spatial:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-spatial-extras:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-spatial3d:jar:6.6.1:compile
[INFO] | +- org.apache.lucene:lucene-suggest:jar:6.6.1:compile
[INFO] | +- org.elasticsearch:securesm:jar:1.2:compile
[INFO] | +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] | +- joda-time:joda-time:jar:2.9.5:compile
[INFO] | +- org.yaml:snakeyaml:jar:1.15:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.6:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.6:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.6:compile
[INFO] | +- com.tdunning:t-digest:jar:3.0:compile
[INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.9.1:compile
[INFO] | - org.elasticsearch:jna:jar:4.4.0-1:compile
[INFO] +- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:5.6.9:compile
[INFO] | +- org.elasticsearch.plugin:parent-join-client:jar:5.6.9:compile
[INFO] | | +- org.locationtech.spatial4j:spatial4j:jar:0.6:compile
[INFO] | | - com.vividsolutions:jts:jar:1.13:compile
[INFO] | - org.elasticsearch.plugin:aggs-matrix-stats-client:jar:5.6.9:compile
[INFO] +- org.elasticsearch.client:elasticsearch-rest-client:jar:5.6.9:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] | +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] | +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] | +- commons-codec:commons-codec:jar:1.10:compile
[INFO] | - commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] +- org.json:json:jar:20171018:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.1:compile
[INFO] | - com.fasterxml.jackson.core:jackson-annotations:jar:2.7.0:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.9.1:compile
[INFO] +- com.apple.extra:ojdbc12c:jar:7.0:compile
[INFO] +- com.apple.extra:oracleucp:jar:12.1:compile
[INFO] +- com.apple.extra:boltlistener:jar:1.0:compile
[INFO] +- com.apple.extra:aqapi13:jar:1.0:compile
[INFO] +- com.apple.extra:BOLTSwitchOver-0.0.1:jar:1.0:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.6:compile
[INFO] +- commons-io:commons-io:jar:2.6:compile
[INFO] - javax.mail:javax.mail-api:jar:1.6.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.516 s
[INFO] Finished at: 2018-06-01T06:05:16-07:00
[INFO] Final Memory: 17M/309M
[INFO] ------------------------------------------------------------------------
01HW1145439:BoltElasticApplier neha922102$

and this gives::::

$ mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building BoltESApplier dev
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.apple.extra:ojdbc12c:jar:7.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:oracleucp:jar:12.1 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:boltlistener:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:aqapi13:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.apple.extra:BOLTSwitchOver-0.0.1:jar:1.0 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.9:tree (default-cli) @ BoltESApplier ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[WARNING] Missing POM for com.apple.extra:ojdbc12c:jar:7.0
[WARNING] Missing POM for com.apple.extra:oracleucp:jar:12.1
[WARNING] Missing POM for com.apple.extra:boltlistener:jar:1.0
[WARNING] Missing POM for com.apple.extra:aqapi13:jar:1.0
[WARNING] Missing POM for com.apple.extra:BOLTSwitchOver-0.0.1:jar:1.0
[INFO] applier:BoltESApplier:jar:dev
[INFO] - org.elasticsearch:elasticsearch:jar:5.6.9:compile
[INFO] +- org.apache.lucene:lucene-core:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-analyzers-common:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-backward-codecs:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-grouping:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-highlighter:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-join:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-memory:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-misc:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-queries:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-queryparser:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-sandbox:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-spatial:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-spatial-extras:jar:6.6.1:compile
[INFO] +- org.apache.lucene:lucene-spatial3d:jar:6.6.1:compile
[INFO] - org.apache.lucene:lucene-suggest:jar:6.6.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.757 s
[INFO] Finished at: 2018-06-01T06:06:10-07:00
[INFO] Final Memory: 18M/443M
[INFO] ------------------------------------------------------------------------

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

This is the icon to use if you are not using markdown format:

image

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.

You probably have somewhere in your classpath an old version of Lucene. Or when you launch your main class, it is missing the dependencies?

when i do "mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene" (output pasted in previou message) , 

I see lucene core jar 6.6.1 version being used.
Actually in this project i am pulling data from kafka to elasticsearch.
No other lucene dependency is declared in pom.xml.

As you can see this field exist in the JAR: https://lucene.apache.org/core/6_6_1/core/org/apache/lucene/util/Version.html#LUCENE_5_4_0

Which means that you have not this dependency at runtime when you execute your method or another older jar is defined before the 6.6.1 in the classpath. You need to double check what you are doing. Specifically, how do you run your code?

I was running in main class, where i was getting this lucene error.

I created a fresh project , copied same pom & code to that new project & the lucene error got resolved.
I was able to use highlevelRestclient.

But now when i run as jar using (java -jar )
i get below error:

$ java -jar dev-0.0.1-SNAPSHOT.jar 
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
	at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:330)
	at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:263)
	at java.util.jar.JarVerifier.processEntry(JarVerifier.java:318)
	at java.util.jar.JarVerifier.update(JarVerifier.java:230)
	at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
	at java.util.jar.JarFile.getInputStream(JarFile.java:450)
	at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:977)
	at sun.misc.Resource.cachedInputStream(Resource.java:77)
	at sun.misc.Resource.getByteBuffer(Resource.java:160)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:454)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

I get this error ONLY when i add this dependency in my pom::

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

This is due to maven shade plugin

Resolved this by adding below to pom.xml

    	<configuration>
								<filters>
									<filter>
										<artifact>*:*</artifact>
										<excludes>
											<exclude>META-INF/*.SF</exclude>
											<exclude>META-INF/*.DSA</exclude>
											<exclude>META-INF/*.RSA</exclude>
										</excludes>
									</filter>
								</filters>

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