Elasticsearch: java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.NamedXContentRegistry

Created on 11 Oct 2017  路  24Comments  路  Source: elastic/elasticsearch

Hello!
I used official guide to install RestHighLevelClient. Elasticsearch 5.6.2
Gradle:

compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '5.6.2'

But after start i have

Caused by: java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.NamedXContentRegistry

in:
new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9300,"http")).build());

I tried to add

compile group: 'org.elasticsearch', name: 'elasticsearch', version: '5.6.2'

Most helpful comment

For anyone running into this same problem and google brought you here:
It's very possible you were using elasticsearch-rest-high-level-client 5.6.x with old version of elasticsearch core library (ex, 2.4.x). This is how I fixed it in Intellij:

  1. Delete the old elasticsearch-2.4.x.jar under External libraries.
  2. Make sure these two decencies are in pom.xml:
  <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.6.5</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>5.6.5</version>
    </dependency>

All 24 comments

First you should follow the guide. It mentions port 9200 not 9300.
Then it鈥檚 better to ask for help on discuss.elastic.co instead.

Check also that gradle or your ide imported all needed libs.
If your still have a problem, create a sample project, push it to GitHub, paste the link in a discuss.elastic.co new thread.

Thanks

For anyone running into this same problem and google brought you here:
It's very possible you were using elasticsearch-rest-high-level-client 5.6.x with old version of elasticsearch core library (ex, 2.4.x). This is how I fixed it in Intellij:

  1. Delete the old elasticsearch-2.4.x.jar under External libraries.
  2. Make sure these two decencies are in pom.xml:
  <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.6.5</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>5.6.5</version>
    </dependency>

Thanks your posts saved my day..
I think the issue still exists with latest Elasticsearch 6.4 documentation as well.. In my case I'm using High level rest client and faced this and solved it by adding appropriate Elasticsearch dependency version as well..
https://stackoverflow.com/questions/52000939/java-exception-while-using-elasticsearch-rest-high-level-client

HI @SantoshKumarA what would you suggest correcting in the documentation? I would love to fix it if there's a mistake but I don't see what is wrong in it. Thanks!

Hi @javanna What I meant was that the link https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.4/java-rest-high-getting-started-maven.html should include Gradle dependency for both

compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.4.0'
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '6.4.0'

Of course the Maven dependency also..

In simple terms, inclusion of dependency for elasticsearch-6.4.0 is missing in the documentation. In my case, without this dependency explicitly mentioned in build.gradle, it was referring to 5.6.10 version and rest-high-level-client was in 6.4.0 and hence I'm unable to run Simple Hello World with Elasticsearch.

Thank you for checking and hope this will be adapted in the documentation.

@SantoshKumarA An explicit elasticsearch dependency should not be necessary, as it is a transitive dependency of the high level rest client. You can see this in the published pom for 6.4.0. Can you please open a discuss issue for your problem? We can better help you there, rather than a closed issue, which can be easily overlooked.

Had the same problem when importing rest-high-level-client versions higher than 6.4.0.
Created an issue hoping the problem to be solved, thanks!

Same problem here, importing client 6.4.1 but must respecify version for elasticsearch core :

compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.4.1'
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '6.4.1'

PS : I am using Gradle to manage project dependencies and tried to run tests with Eclipse JUnit plugin

@pilak Sorry for your trouble. This issue is already fixed for 6.5.0 (the problem was packaging type was inadvertently set to pom for the high level client jar).

Hi, how can I get access to 6.5 version? The Elastic snapshot repository doesn't work (https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.x/java-rest-high-getting-started-maven.html)

hi @generiscorp what's wrong with the snapshot repository? I double checked and everything looks fine in there.

I found a different snapshot repository than the one in Elastic docs, but the build from yesterday doesn't fix the issue, still v5.6.11 shows up in dependencies.
(https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/client/rest-high-level/6.5.0-SNAPSHOT/)

https://snapshots.elastic.co/maven/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.5.0-SNAPSHOT/elasticsearch-rest-high-level-client-6.5.0-SNAPSHOT.jar is the right link. The version should contain the -SNAPSHOT suffix in the docs, not sure why it does not at the moment.

Thank you, but with the snapshot from yesterday I stil experience the same issue. Maven downloads org.elasticsearch-elasticsearch 5.6.11 instead of 6.5

@javanna this is what mvn dependency:tree shows:

[INFO] +- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:6.5.0-SNAPSHOT:compile
[INFO] | +- org.elasticsearch:elasticsearch:jar:5.6.11:compile
[INFO] | | +- org.apache.lucene:lucene-core:jar:6.6.1:compile
[INFO] | | +- org.apache.lucene:lucene-analyzers-common:jar:6.6.1:compile

I do not see anything wrong with the pom file uploaded there: https://snapshots.elastic.co/maven/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.5.0-SNAPSHOT/elasticsearch-rest-high-level-client-6.5.0-SNAPSHOT.pom . Maybe the 5.6.11 comes in from some other dependency, but it should not come as a dependency of the high-level REST client version 6.5.0-SNAPSHOT. Please open a post in our discuss forum if you need help. Thanks!

@javanna thank you, we found it was actually silently overwritten by some Spring Boot dependency.

Hi @mariuszpala it seems that I got same issues in my springboot project. I added version 6.4.2 elasticsearch maven dependency. When I checked my version 6.4.2 elasticsearch-rest-high-level-client maven dependency, it got elasticsearch maven dependency with version 2.4.6 instead of version 6.4.2. Can you share some of your experience for sloving the problem?

Hi @bugmakesprogress, the root cause was the "parent" spring boot dependency which had older version referenced. We removed "parent" and added it as a regular dependency as below and now it works fine:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${org.springframework.version}</version> </dependency>

With the tip from @mariuszpala I think the conflict comes from the pom.xml in spring-boot-dependencies (spring-boot-starter-parent points to this).

For example, I was seeing the same behavior while using Spring Boot 2.0.4 and if you look at https://github.com/spring-projects/spring-boot/blob/2.0.x/spring-boot-project/spring-boot-dependencies/pom.xml you can see the <dependencyManagement> section has an older version of elasticsearch specified.

Since I want my parent to be spring-boot-starter-parent I'll just have to explicitly override their elasticsearch version.

Yep, this is a Spring Boot problem. Especially created by the Spring Dependency plugin in Gradle only.

Same issue with version 7 as well, solved by adding elastic search dependency as well.

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

This is a Spring Boot problem. solved by adding properties

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <elasticsearch.version>6.8.0</elasticsearch.version>
</properties>
Was this page helpful?
0 / 5 - 0 ratings