【问题标题】:ElasticSearch library in Java not able to find AggregationBuilders.sum methodJava 中的 ElasticSearch 库无法找到 AggregationBuilders.sum 方法
【发布时间】:2020-02-04 13:28:00
【问题描述】:

我正在尝试在 java 中使用 ElasticSearch 的 AggregationBuilders api 来查找总和聚合。但是在使用使用此 (AggregationBuilders.sum()) 方法的服务时,它会给出以下错误:

java.lang.NoSuchMethodError:org.elasticsearch.search.aggregations.;

这是我的 pom.xml 文件

    <dependencies>
        <!-- Elasticsearch dependencies -->
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/transport-netty4-client -->
        <dependency>
            <groupId>org.elasticsearch.plugin</groupId>
            <artifactId>transport-netty4-client</artifactId>
            <version>7.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.2.0.M1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-core</artifactId>
            <version>2.0.0.M2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.1.0.BUILD-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <version>2.1.5.RELEASE</version>
        </dependency>

    </dependencies>```


到目前为止,我已经尝试清理 .m2 并再次运行全新安装,但仍然会出现此错误。 任何帮助将不胜感激:

PS:更改 pom 后,我可以停止安装 elasticsearch 6.5,但仍在安装 6.4.3。我只想要 7.2 版本。知道如何找到导致其他版本安装的依赖项

es 模块的新 Pom

        <!-- Elasticsearch dependencies -->
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/transport-netty4-client -->
        <!--<dependency>
            <groupId>org.elasticsearch.plugin</groupId>
            <artifactId>transport-netty4-client</artifactId>
            <version>7.2.0</version>
        </dependency>-->

       <!-- <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-core</artifactId>
            <version>2.0.0.M2</version>
            <scope>compile</scope>
        </dependency>-->
     

    </dependencies>

这是聚合器项目的pom:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dummy.proj</groupId>
    <artifactId>dummy-proj</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>es</module>
        <module>ms</module>
    </modules>

    <properties>
        <!-- These Properties are common for all spring R&D for maven build-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
       
        <common.lang.version>2.4</common.lang.version>
        <dummy.version>1.0-SNAPSHOT</dummy.version>
        <lombok.version>1.16.18</lombok.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>
       
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.10.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.10.0</version>
        </dependency>
    </dependencies>

<!--

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>
-->


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>```

【问题讨论】:

  • 您能否运行mvn dependency:tree -Dverbose -Dincludes=org.elasticsearch 并查看您是否有多个相互冲突的 Elasticsearch 版本。除了导入自己的 ES 版本之外,使用 Spring Boot 和 Spring Data 时经常出现这种情况。
  • 是的,它是这样给出的:[INFO] +- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:7.2.0:compile [INFO] | \- (org.elasticsearch:elasticsearch:jar:7.2.0:compile - 重复省略) [INFO] \- org.springframework.data:spring-data-elasticsearch:jar:3.2.0.M1:compile [INFO] \- org.elasticsearch.client:transport:jar:6.5.0:compile [INFO] \- (org.elasticsearch:elasticsearch:jar:6.5.0:compile - 与 7.2.0 冲突省略)
  • 这样,您可以混合使用 ES 6.5.0(由 Spring Boot/Data ES 导入)和 7.2.0(手动导入)...如果您解决了这个问题,那么您就是很高兴。
  • 我能够阻止 ES 6.5 但 6.4.3 仍在安装.. 知道如何检查导致安装 es 6.4.3 的依赖关系

标签: java maven elasticsearch spring-data-elasticsearch


【解决方案1】:

Spring Data Elasticsearch 3.2 不适用于 Elasticsearch 7; 3.2.0.GA 使用 Elasticsearch 6.8。

对 Easticsearch 7 的支持和适配在现在的 master 分支中,稍后将成为版本 4

【讨论】:

  • 我在 pom 中将我的 ElasticSearch 版本更改为 6.8 并且它有效!!!非常感谢..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-19
  • 1970-01-01
  • 2011-05-05
  • 2018-07-31
  • 1970-01-01
  • 2016-02-11
  • 1970-01-01
相关资源
最近更新 更多