javaelasticsearchelasticsearch-5buildpathelasticsearch-7

Configure build path problem in eclipse - java


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


Solution

  • 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!