1

I upgraded the elastic search from version 5.5 to 7.7, everything is working as expected. But when I try to get the Total hits, I get the following error

searchResponse.getHits().getTotalHits()

The type org.apache.lucene.search.TotalHits cannot be resolved. It is indirectly referenced from required .class files

We are not using the lucene library but still, it says it refers to the lucene, Any help is appreciated to fix this.

enter image description here

Maven pom.xml :

I have only these two Jars,

<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>7.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.11.1</version>
        </dependency>

Thanks,
Harry

Harry
  • 3,072
  • 6
  • 43
  • 100
  • Could you please update the question with your maven/gradle config, looks like lucene library is missing. – Kamal Kunjapur Jun 16 '20 at 07:59
  • @OpsterESNinja-Kamal Updated the pom.xml but previously may be the jars on lucene could have been there, which I removed now – Harry Jun 16 '20 at 08:40
  • You can either go with the below answer if you have not removed the lucene jars or use this [link](https://stackoverflow.com/a/2556197/3838328) so that maven re-downloads the required dependencies. – Kamal Kunjapur Jun 16 '20 at 08:56

1 Answers1

2

As mentioned this link, you probably need to add the below dependency:

<repository>
    <id>elastic-lucene-snapshots</id>
    <name>Elastic Lucene Snapshots</name>
    <url>https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>false</enabled></snapshots>
</repository>

Also as per this link, you may also need to add Log4j dependency as well:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.1</version>
</dependency>

That should do the trick.

Alternatively you can also add the below lucene dependency with the exact version you can see if you just do http://<hostname>:9200, however I suggest the above approach and go as per their documentation.

<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-core</artifactId>
    <version>8.5.1</version>
</dependency>

Hope that helps!

Kamal Kunjapur
  • 8,547
  • 2
  • 22
  • 32