Error nested exception is java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits()

Hi guys,
I'm using spring boot 2.1.1 connect to Elasticsearch 7.3.4 (elastic was run on docker).
Spring application startup and connected to the Elasticsearch but when I try to search may document on Elastic I got the error:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits()J

My Search query like below:

NativeSearchQuery build = new NativeSearchQueryBuilder()
                .withQuery(QueryBuilders.matchAllQuery())
                .withPageable(new PageRequest(0, 10))
                .build();
        List<FullProfile> articles = elasticsearchTemplate.queryForList(build,FullProfile.class);

Can you guys help me to resolve this problem.
Thanks

hey,

providing the full exception would help.

Is it possible, that you are using a newer/older Elasticsearch dependency, that Spring Boot is using/requiring? Are you overriding dependencies somewhere?

--Alex

When using springboot with
elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:

<properties>
  <elasticsearch.version>7.3.0<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions

Yes I already tried with version 7.3.4 in my pom.xml file before I bring my problem to here.
But I still got error.
Currently I switch to Elasticsearch 6.6.2 and anything work great.
Of course I also have to specify elastic version in pom.xml.
Later on I will try with version 7.3.4 again.
Anyway thanks for your answer.

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