New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.NamedXContentRegistry #26959

Closed
vnikolaenko opened this Issue Oct 11, 2017 · 20 comments

Comments

Projects
None yet
@vnikolaenko

vnikolaenko commented Oct 11, 2017

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'

@dadoonet

This comment has been minimized.

Member

dadoonet commented Oct 11, 2017

First you should follow the guide. It mentions port 9200 not 9300.
Then it’s 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

@dadoonet dadoonet closed this Oct 11, 2017

@yytsui

This comment has been minimized.

yytsui commented Dec 13, 2017

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

This comment has been minimized.

SantoshKumarA commented Aug 24, 2018

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

@javanna

This comment has been minimized.

Member

javanna commented Aug 24, 2018

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!

@SantoshKumarA

This comment has been minimized.

SantoshKumarA commented Aug 24, 2018

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.

@rjernst

This comment has been minimized.

Member

rjernst commented Aug 24, 2018

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

@sujieim

This comment has been minimized.

sujieim commented Oct 8, 2018

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!

@pilak

This comment has been minimized.

pilak commented Oct 22, 2018

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

@rjernst

This comment has been minimized.

Member

rjernst commented Oct 23, 2018

@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).

@generiscorp

This comment has been minimized.

generiscorp commented Oct 25, 2018

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)

@javanna

This comment has been minimized.

Member

javanna commented Oct 25, 2018

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

@generiscorp

This comment has been minimized.

generiscorp commented Oct 25, 2018

@mariuszpala

This comment has been minimized.

mariuszpala commented Oct 25, 2018

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

@javanna

This comment has been minimized.

Member

javanna commented Oct 25, 2018

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.

@mariuszpala

This comment has been minimized.

mariuszpala commented Oct 25, 2018

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

@mariuszpala

This comment has been minimized.

mariuszpala commented Oct 25, 2018

@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

@javanna

This comment has been minimized.

Member

javanna commented Oct 25, 2018

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!

@mariuszpala

This comment has been minimized.

mariuszpala commented Oct 25, 2018

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

@bugmakesprogress

This comment has been minimized.

bugmakesprogress commented Nov 9, 2018

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?

@mariuszpala

This comment has been minimized.

mariuszpala commented Nov 9, 2018

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:

			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment