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

**URL:** <https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [September 24, 2019, 2:27am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774 "2019-09-24T02:27:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luongky06](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luongky06/32/54761_2.png) [@luongky06](https://discuss.elastic.co/u/luongky06)\
**Post date:** [September 24, 2019, 2:27am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774/1 "2019-09-24T02:27:50Z")

</div>

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:

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

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

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 24, 2019, 8:45am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774/2 "2019-09-24T08:45:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 24, 2019, 8:48am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774/3 "2019-09-24T08:48:24Z")

</div>

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

```auto
<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](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions)

---

<div class="post-metadata">

**Author:** ![luongky06](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luongky06/32/54761_2.png) [@luongky06](https://discuss.elastic.co/u/luongky06)\
**Post date:** [October 1, 2019, 8:57am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774/4 "2019-10-01T08:57:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 29, 2019, 8:57am UTC](https://discuss.elastic.co/t/error-nested-exception-is-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/200774/5 "2019-10-29T08:57:13Z")

</div>

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