gpt4 book ai didi

java - 带有 Spring Data Elasticsearch 的 Elasticsearch Rest Client

转载 作者:太空狗 更新时间:2023-10-30 19:37:15 26 4
gpt4 key购买 nike

我正在使用 Spring boot 和 AWS elasticsearch 服务。仅提供 REST 接口(interface)的 AWS Elasticsearch 服务。

Elasticsearch Rest 客户端是 here .

简单地说,是否可以将 REST 客户端与 Spring Data Elasticsearch 一起使用?

换句话说,Spring Data Elasticsearch 是否与 Elasticsearch Rest 客户端一起使用?

Spring Data Elasticsearch 非常易于使用,模板提供了我需要的大部分功能。使用 Elasicsearch Rest 客户端时,我必须自己实现所有功能。

最佳答案

[2020 年 5 月更新]

https://spring.io/blog/2020/05/27/what-s-new-in-spring-data-elasticsearch-4-0

正如您可以阅读 Spring Data Elasticsearch 4.0:

Spring Data Elasticsearch now uses Elasticsearch 7, 7.6.2 in particular. Elasticsearch clusters running on 6.x versions are not supported anymore. The ElasticsearchTemplate class is deprecated as it uses the TransportClient to access Elasticsearch, which itself is deprecated since Elasticsearch version 7.+ Users should switch to ElasticsearchRestTemplate or ReactiveElasticsearchTemplate.

[2019 年 2 月更新]

现在看到 3.2.0 M1 Spring Data Elasticsearch 支持 HTTP 客户端 ( https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/reference/html/#reference )

根据文档(它当然可以更改,因为它不是最终版本,所以我将它放在这里):

The well known TransportClient is deprecated as of Elasticsearch 7.0.0 and is expected to be removed in Elasticsearch 8.0.

2.1. High Level REST Client

The Java High Level REST Client provides a straight forward replacement for the TransportClient as it accepts and returns the very same request/response objects and therefore depends on the Elasticsearch core project. Asynchronous calls are operated upon a client managed thread pool and require a callback to be notified when the request is done.

示例 49. 高级 REST 客户端

static class Config {

@Bean
RestHighLevelClient client() {

ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200", "localhost:9201")
.build();

return RestClients.create(clientConfiguration).rest();
}
}

// ...

IndexRequest request = new IndexRequest("spring-data", "elasticsearch", randomID())
.source(singletonMap("feature", "high-level-rest-client"))
.setRefreshPolicy(IMMEDIATE);

IndexResponse response = client.index(request);

[原始答案]

目前 Spring Data Elasticsearch 不支持通过 REST API 进行通信。他们正在使用传输客户端。

有一个独立的 Spring Data Elasticsearch 分支(这个人和你一样需要 AWS),其中使用 JEST 库并通过 REST 进行通信:

https://github.com/VanRoy/spring-data-jest

你会在Spring Data Elasticsearch的勾选下面找到有趣的讨论:

https://jira.spring.io/browse/DATAES-220

根据 Elasticsearch 团队的说法,他们计划只支持 ES 的 HTTP 通信,我认为 Spring Data Elasticseach 将来需要迁移到 REST。

希望对您有所帮助。

关于java - 带有 Spring Data Elasticsearch 的 Elasticsearch Rest Client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com