在 eclipse 中配置构建路径问题 - java

Configure build path problem in eclipse - java

我将弹性搜索从 5.5 版升级到 7.7 版,一切正常。 但是当我尝试获取总点击数时,出现以下错误

searchResponse.getHits().getTotalHits()

无法解析类型 org.apache.lucene.search.TotalHits。它是从必需的 .class 文件

中间接引用的

我们没有使用 lucene 库,但它仍然说它指的是 lucene, 感谢您提供任何帮助来解决此问题。

Maven pom.xml :

我只有这两个罐子,

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

谢谢,
哈利

如前所述this link,您可能需要添加以下依赖项:

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

此外,根据 this link,您可能还需要添加 Log4j 依赖项:

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

这应该可以解决问题。

或者,您也可以添加下面的 lucene 依赖项以及您可以看到的确切版本,如果您只是这样做 http://<hostname>:9200,但是我建议使用上述方法并按照他们的文档进行操作。

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

希望对您有所帮助!