[英]elasticsearch java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.formatSegments
I'm trying this basic elasticsearch example from there guide to use java client API in a spring boot project.我正在尝试这个基本的 elasticsearch 示例,该示例在 spring 引导项目中使用 java 客户端 API 指南。
but it gives me the following error when running:但它在运行时给我以下错误:
java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.formatSegments([Ljava/lang/String;)Ljava/lang/String;
here is my POM file .这是我的POM 文件。
the code:代码:
public void retrieveAuditMessages() throws IOException {
// Create the low-level client
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200)
).build();
// Create the transport with a Jackson mapper
ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper()
);
// Create the API client
ElasticsearchClient client = new ElasticsearchClient(transport);
SearchResponse<String> search = client.search(s -> s
.index("logstash-wildfly*")
.query(q -> q
.term(t -> t
.field("host")
.value(v -> v.stringValue("aboSaadoosh"))
)
),
String.class);
for(Hit<String> hit: search.hits().hits())
{
System.out.println(hit.source());
}
}
I guess it's a problem with dependencies, but I don't know how to solve it.我猜是依赖关系的问题,但我不知道如何解决。
I'm using Elasticsearch version 8.1.1
java client API
and spring boot 1.5.7.RELEASE
我正在使用 Elasticsearch 版本
8.1.1
java client API
和 spring 启动1.5.7.RELEASE
I solved this by adding org.apache.httpcomponents:httpclient:4.5.13
explicitly in the POM file (instead of version org.apache.httpcomponents:httpclient:4.5.3
included by co.elastic.clients:elasticsearch-java:8.1.1
)我通过在 POM 文件中明确添加
org.apache.httpcomponents:httpclient:4.5.13
解决了这个问题(而不是 co.elastic.clients: co.elastic.clients:elasticsearch-java:8.1.1
包含的版本org.apache.httpcomponents:httpclient:4.5.3
。 co.elastic.clients:elasticsearch-java:8.1.1
)
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
I don't know if this is the correct way to solve it but anyway it worked for me.我不知道这是否是解决问题的正确方法,但无论如何它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.