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

**URL:** <https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592>\
**Category:** Elasticsearch\
**Created:** [April 5, 2020, 7:56pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592 "2020-04-05T19:56:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 5, 2020, 7:57pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/1 "2020-04-05T19:57:00Z")

</div>

Hello guys, I know this topic has already been opened but I couldn't see any solution. I am using spring boot 2.2.6 with ES 7.6.2, spring data commons 2.2.6.

I defined my repository like this:

```auto
public interface CollaboratorRepository extends ElasticsearchRepository<Collaborator, String> {
	
}

```

In my CollaboratorService, I call collaboratorRepository.findAll().

I get  
java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits()J  
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.doCount(ElasticsearchRestTemplate.java:628) ~[spring-data-elasticsearch-3.2.6.RELEASE.jar:3.2.6.RELEASE]

Has someone an idea of the error origin ?

---

<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:** [April 5, 2020, 8:08pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/2 "2020-04-05T20:08:00Z")

</div>

Welcome!

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.6.2<elasticsearch.version>
</properties>

```

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

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 5, 2020, 8:36pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/3 "2020-04-05T20:36:10Z")

</div>

Thank you @dadoonet.

But I am using gradle and in my build.gradle, I declare the dependencies like this:

```auto
ext {
	springBootVersion = '2.2.6.RELEASE',
	elasticSearchVersion = '7.6.2'
}

dependencies {
    implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
    compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
    compile "org.springframework.data:spring-data-commons:${springBootVersion}"
    compile "org.springframework.data:spring-data-elasticsearch:3.2.6.RELEASE"
    compile "org.elasticsearch.client:elasticsearch-rest-high-level-client:${elasticSearchVersion}"
    compile "org.elasticsearch.client:elasticsearch-rest-client:${elasticSearchVersion}"
	compile "org.elasticsearch:elasticsearch:${elasticSearchVersion}"
    implementation "io.springfox:springfox-swagger2:2.8.0"
    implementation "io.springfox:springfox-swagger-ui:2.8.0"
    implementation "javax.xml.bind:jaxb-api"
    implementation "org.projectlombok:lombok"
    testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
    testCompile "junit:junit:4.12"
}

```

---

<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:** [April 6, 2020, 1:27am UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/4 "2020-04-06T01:27:11Z")

</div>

Is there a way to get the dependency tree in Gradle?

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 7, 2020, 4:32pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/5 "2020-04-07T16:32:26Z")

</div>

Of course @dadoonet but the dependency tree is very verbose.

---

<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:** [April 7, 2020, 5:14pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/6 "2020-04-07T17:14:14Z")

</div>

Share it on [gist.github.com](http://gist.github.com) if too big.

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 7, 2020, 5:28pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/7 "2020-04-07T17:28:20Z")

</div>

The link: [https://gist.github.com/ajnfde/6b59657870c5f277ea07de11a639b014](https://gist.github.com/ajnfde/6b59657870c5f277ea07de11a639b014)

---

<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:** [April 7, 2020, 6:21pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/8 "2020-04-07T18:21:27Z")

</div>

I think that the way you wrote Elasticsearch version is wrong. May be it should be `elasticsearchVersion` and not `elasticSearchVersion`.

Look at this:

```
 org.elasticsearch.client:transport:6.8.7
```

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 8, 2020, 5:02pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/9 "2020-04-08T17:02:04Z")

</div>

According to the dependency tree, the transport jar is brought by spring-data-elasticsearch.

So I have updated my build.gradle by asking gradle to not include transport jar when it imports spring-data-elasticsearch. And I have declared clearly `org.elasticsearch.client:transport:7.6.2`

The issue always appears.

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 8, 2020, 5:04pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/10 "2020-04-08T17:04:12Z")

</div>

Here the dependencies declarations

```auto
dependencies {
    compile "org.elasticsearch:elasticsearch:7.6.2"
    compile "org.elasticsearch.client:transport:7.6.2"
    implementation "org.springframework.boot:spring-boot-starter:2.2.6.RELEASE"
    compile "org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE"
    compile "org.springframework.data:spring-data-commons:2.2.6.RELEASE"
    compile ("org.springframework.data:spring-data-elasticsearch:3.2.6.RELEASE"){
      exclude group: 'org.elasticsearch.client', module: 'transport'
      exclude group: 'org.elasticsearch.client', module: 'elasticsearch-rest-high-level-client'
    }
    compile "org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.2"
    compile "org.elasticsearch.client:elasticsearch-rest-client:7.6.2"
    implementation "io.springfox:springfox-swagger2:2.8.0"
    implementation "io.springfox:springfox-swagger-ui:2.8.0"
    implementation "javax.xml.bind:jaxb-api"
    implementation "org.projectlombok:lombok"
    testImplementation "org.springframework.boot:spring-boot-starter-test:2.2.6.RELEASE"
    testCompile "junit:junit:4.12"
}

```

---

<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:** [April 9, 2020, 1:49am UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/11 "2020-04-09T01:49:33Z")

</div>

Did you check the dependency tree again?

---

<div class="post-metadata">

**Author:** ![Serkan\_Akdemir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serkan_akdemir/32/65995_2.png) [@Serkan\_Akdemir](https://discuss.elastic.co/u/Serkan_Akdemir)\
**Post date:** [April 9, 2020, 12:25pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/12 "2020-04-09T12:25:28Z")

</div>

I had similar issue with "7.6.2". "spring-data-elasticsearch 3.2.6.RELEASE" expects "long" value but ES returns getTotalHits as "TotalHits" type inside "ElasticsearchRestTemplate" class.

---

<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:** [April 9, 2020, 2:11pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/13 "2020-04-09T14:11:31Z")

</div>

That's because of the transitive dependencies IMO.

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 11, 2020, 2:58pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/14 "2020-04-11T14:58:51Z")

</div>

@Serkan_Akdemir what do you recommand ?

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 11, 2020, 3:02pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/15 "2020-04-11T15:02:51Z")

</div>

Here the dependency tree

```auto
+--- org.elasticsearch:elasticsearch:7.6.2
| +--- org.elasticsearch:elasticsearch-core:7.6.2
| +--- org.elasticsearch:elasticsearch-secure-sm:7.6.2
| +--- org.elasticsearch:elasticsearch-x-content:7.6.2
| | +--- org.elasticsearch:elasticsearch-core:7.6.2
| | +--- org.yaml:snakeyaml:1.17 -> 1.25
| | +--- com.fasterxml.jackson.core:jackson-core:2.8.11 -> 2.10.3
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.8.11 -> 2.10.3
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.11 -> 2.10.3
| | \--- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.8.11 -> 2.10.3
| +--- org.elasticsearch:elasticsearch-geo:7.6.2
| +--- org.apache.lucene:lucene-core:8.4.0
| +--- org.apache.lucene:lucene-analyzers-common:8.4.0
| +--- org.apache.lucene:lucene-backward-codecs:8.4.0
| +--- org.apache.lucene:lucene-grouping:8.4.0
| +--- org.apache.lucene:lucene-highlighter:8.4.0
| +--- org.apache.lucene:lucene-join:8.4.0
| +--- org.apache.lucene:lucene-memory:8.4.0
| +--- org.apache.lucene:lucene-misc:8.4.0
| +--- org.apache.lucene:lucene-queries:8.4.0
| +--- org.apache.lucene:lucene-queryparser:8.4.0
| +--- org.apache.lucene:lucene-sandbox:8.4.0
| +--- org.apache.lucene:lucene-spatial:8.4.0
| +--- org.apache.lucene:lucene-spatial-extras:8.4.0
| +--- org.apache.lucene:lucene-spatial3d:8.4.0
| +--- org.apache.lucene:lucene-suggest:8.4.0
| +--- org.elasticsearch:elasticsearch-cli:7.6.2
| | +--- net.sf.jopt-simple:jopt-simple:5.0.2
| | \--- org.elasticsearch:elasticsearch-core:7.6.2
| +--- com.carrotsearch:hppc:0.8.1
| +--- joda-time:joda-time:2.10.4 -> 2.10.5
| +--- com.tdunning:t-digest:3.2
| +--- org.hdrhistogram:HdrHistogram:2.1.9
| +--- org.apache.logging.log4j:log4j-api:2.11.1 -> 2.12.1
| \--- org.elasticsearch:jna:4.5.1
+--- org.elasticsearch.client:transport:7.6.2
| +--- org.elasticsearch:elasticsearch:7.6.2 (*)
| +--- org.elasticsearch.plugin:transport-netty4-client:7.6.2 -> 6.8.7
| | +--- io.netty:netty-buffer:4.1.32.Final -> 4.1.48.Final
| | +--- io.netty:netty-codec:4.1.32.Final -> 4.1.48.Final
| | +--- io.netty:netty-codec-http:4.1.32.Final -> 4.1.48.Final
| | | \--- io.netty:netty-handler:4.1.48.Final
| | +--- io.netty:netty-common:4.1.32.Final -> 4.1.48.Final
| | +--- io.netty:netty-handler:4.1.32.Final -> 4.1.48.Final
| | +--- io.netty:netty-resolver:4.1.32.Final -> 4.1.48.Final
| | \--- io.netty:netty-transport:4.1.32.Final -> 4.1.48.Final
| +--- org.elasticsearch.plugin:reindex-client:7.6.2
| | +--- org.elasticsearch.client:elasticsearch-rest-client:7.6.2
| | | +--- org.apache.httpcomponents:httpclient:4.5.10 -> 4.5.12
| | | +--- org.apache.httpcomponents:httpcore:4.4.12 -> 4.4.13
| | | +--- org.apache.httpcomponents:httpasyncclient:4.1.4
| | | +--- org.apache.httpcomponents:httpcore-nio:4.4.12 -> 4.4.13
| | | \--- commons-codec:commons-codec:1.11 -> 1.13
| | \--- org.elasticsearch:elasticsearch-ssl-config:7.6.2
| | \--- org.elasticsearch:elasticsearch-core:7.6.2
| +--- org.elasticsearch.plugin:lang-mustache-client:7.6.2
| | \--- com.github.spullara.mustache.java:compiler:0.9.6
| +--- org.elasticsearch.plugin:percolator-client:7.6.2
| +--- org.elasticsearch.plugin:parent-join-client:7.6.2
| \--- org.elasticsearch.plugin:rank-eval-client:7.6.2
+--- org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE
| | +--- org.springframework.boot:spring-boot:2.2.6.RELEASE
| | | +--- org.springframework:spring-core:5.2.5.RELEASE
| | | | \--- org.springframework:spring-jcl:5.2.5.RELEASE
| | | \--- org.springframework:spring-context:5.2.5.RELEASE
| | | +--- org.springframework:spring-aop:5.2.5.RELEASE
| | | | +--- org.springframework:spring-beans:5.2.5.RELEASE
| | | | | \--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | | | \--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
| | | +--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | | \--- org.springframework:spring-expression:5.2.5.RELEASE
| | | \--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.2.6.RELEASE
| | | \--- org.springframework.boot:spring-boot:2.2.6.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-starter-logging:2.2.6.RELEASE
| | | +--- ch.qos.logback:logback-classic:1.2.3
| | | | +--- ch.qos.logback:logback-core:1.2.3
| | | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | +--- org.apache.logging.log4j:log4j-to-slf4j:2.12.1
| | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | | \--- org.apache.logging.log4j:log4j-api:2.12.1
| | | \--- org.slf4j:jul-to-slf4j:1.7.30
| | | \--- org.slf4j:slf4j-api:1.7.30
| | +--- jakarta.annotation:jakarta.annotation-api:1.3.5
| | +--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | \--- org.yaml:snakeyaml:1.25
| +--- org.springframework.boot:spring-boot-starter-json:2.2.6.RELEASE
| | +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
| | +--- org.springframework:spring-web:5.2.5.RELEASE
| | | +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
| | | \--- org.springframework:spring-core:5.2.5.RELEASE (*)
| | +--- com.fasterxml.jackson.core:jackson-databind:2.10.3
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
| | | \--- com.fasterxml.jackson.core:jackson-core:2.10.3
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.3
| | | +--- com.fasterxml.jackson.core:jackson-core:2.10.3
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.3
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
| | | +--- com.fasterxml.jackson.core:jackson-core:2.10.3
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
| | \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.3
| | +--- com.fasterxml.jackson.core:jackson-core:2.10.3
| | \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
| +--- org.springframework.boot:spring-boot-starter-tomcat:2.2.6.RELEASE
| | +--- jakarta.annotation:jakarta.annotation-api:1.3.5
| | +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
| | +--- org.apache.tomcat.embed:tomcat-embed-el:9.0.33
| | \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.33
| | \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
| +--- org.springframework.boot:spring-boot-starter-validation:2.2.6.RELEASE
| | +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
| | +--- jakarta.validation:jakarta.validation-api:2.0.2
| | \--- org.hibernate.validator:hibernate-validator:6.0.18.Final
| | +--- org.jboss.logging:jboss-logging:3.3.2.Final -> 3.4.1.Final
| | \--- com.fasterxml:classmate:1.3.4 -> 1.5.1
| +--- org.springframework:spring-web:5.2.5.RELEASE (*)
| \--- org.springframework:spring-webmvc:5.2.5.RELEASE
| +--- org.springframework:spring-aop:5.2.5.RELEASE (*)
| +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
| +--- org.springframework:spring-context:5.2.5.RELEASE (*)
| +--- org.springframework:spring-core:5.2.5.RELEASE (*)
| +--- org.springframework:spring-expression:5.2.5.RELEASE (*)
| \--- org.springframework:spring-web:5.2.5.RELEASE (*)
+--- org.springframework.data:spring-data-commons:2.2.6.RELEASE
| +--- org.springframework:spring-core:5.2.5.RELEASE (*)
| +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
| \--- org.slf4j:slf4j-api:1.7.26 -> 1.7.30
+--- org.springframework.data:spring-data-elasticsearch:3.2.6.RELEASE
| +--- org.springframework:spring-context:5.2.5.RELEASE (*)
| +--- org.springframework:spring-tx:5.2.5.RELEASE
| | +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
| | \--- org.springframework:spring-core:5.2.5.RELEASE (*)
| +--- org.springframework.data:spring-data-commons:2.2.6.RELEASE (*)
| +--- joda-time:joda-time:2.10.5
| +--- org.elasticsearch.plugin:transport-netty4-client:6.8.7 (*)
| +--- com.fasterxml.jackson.core:jackson-core:2.10.3
| +--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
| \--- org.slf4j:slf4j-api:1.7.26 -> 1.7.30
+--- org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.2
| +--- org.elasticsearch:elasticsearch:7.6.2 (*)
| +--- org.elasticsearch.client:elasticsearch-rest-client:7.6.2 (*)
| +--- org.elasticsearch.plugin:mapper-extras-client:7.6.2
| +--- org.elasticsearch.plugin:parent-join-client:7.6.2
| +--- org.elasticsearch.plugin:aggs-matrix-stats-client:7.6.2
| +--- org.elasticsearch.plugin:rank-eval-client:7.6.2
| \--- org.elasticsearch.plugin:lang-mustache-client:7.6.2 (*)
\--- org.elasticsearch.client:elasticsearch-rest-client:7.6.2 (*)

```

---

<div class="post-metadata">

**Author:** ![suryas16](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@suryas16](https://discuss.elastic.co/u/suryas16)\
**Post date:** [April 12, 2020, 1:32am UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/16 "2020-04-12T01:32:06Z")

</div>

Hi Team,

I do have the same issue, with the same with 3.2.6 and 7.6.1versions:

```auto
java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits()J
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.doCount(ElasticsearchRestTemplate.java:606) ~[spring-data-elasticsearch-3.2.6.RELEASE.jar:3.2.6.RELEASE]

```

Did anyone find a solution to it?

---

<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:** [April 12, 2020, 4:04am UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/17 "2020-04-12T04:04:30Z")

</div>

You need to use Spring Data Elasticsearch 4.0.0.RC1.

[https://docs.spring.io/spring-data/elasticsearch/docs/4.0.0.RC1/reference/html/#reference](https://docs.spring.io/spring-data/elasticsearch/docs/4.0.0.RC1/reference/html/#reference)

---

<div class="post-metadata">

**Author:** ![Serkan\_Akdemir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serkan_akdemir/32/65995_2.png) [@Serkan\_Akdemir](https://discuss.elastic.co/u/Serkan_Akdemir)\
**Post date:** [April 12, 2020, 12:16pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/18 "2020-04-12T12:16:08Z")

</div>

As @dadoonet mentioned, either use 4.0.0.RC1or use direct elasticsearch java api instead of Spring-data-es.

---

<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:** [April 12, 2020, 12:38pm UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/19 "2020-04-12T12:38:03Z")

</div>

> [@Serkan\_Akdemir](#):
>
> or use direct elasticsearch java api

You can look at this sample application for this:

> **[GitHub - dadoonet/legacy-search at 06-fuzziness](https://github.com/dadoonet/legacy-search/tree/06-fuzziness)**
>
> 06-fuzziness

---

<div class="post-metadata">

**Author:** ![ajnfde3](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@ajnfde3](https://discuss.elastic.co/u/ajnfde3)\
**Post date:** [April 25, 2020, 10:13am UTC](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592/20 "2020-04-25T10:13:05Z")

</div>

Thank you @dadoonet and @Serkan_Akdemir. I will try your solutions. Definitely I think there is a mistake either in the spring-data-elasticsearch 3.2.6.release version, either in the elasticsearch 7.6.2 version.

In spring-data-elasticsearch 3.2.6.release version, the method `doCount` of `ElasticsearchRestTemplate` class has to return a **long value** but it returns `response.getHits().getTotalHits()` which refers to `SearchHits` class `getTotalHits()` method which return **`TotalHits`** object.

[Next page](https://discuss.elastic.co/t/error-java-lang-nosuchmethoderror-org-elasticsearch-search-searchhits-gettotalhits/226592.md?page=2)
