Elasticsearch Rest Client with Spring Data Elasticsearch [英] Elasticsearch Rest Client with Spring Data Elasticsearch

查看:63
本文介绍了Elasticsearch Rest Client with Spring Data Elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在使用的是 Spring Boot 和 AWS elasticsearch 服务.仅提供 REST 接口的 AWS Elasticsearch 服务.

I am in a situation where I am using Spring boot and AWS elasticsearch service. AWS Elasticsearch service which only provides REST interface.

Elasticsearch Rest Client 这里.

Elasticsearch Rest Client is here.

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

Simply, Is it possible to use REST client with Spring Data Elasticsearch?

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

In other words, Does Spring Data Elasticsearch works with Elasticsearch Rest client?

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

Spring Data Elasticsearch is very easy to use and template provides very most functionality that I need. With Elasicsearch Rest client I have to implement all the functionality myself.

推荐答案

[2020 年 5 月更新]

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

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

As you can read Spring Data Elasticsearch 4.0:

Spring Data Elasticsearch 现在特别使用 Elasticsearch 7,7.6.2.不再支持在 6.x 版本上运行的 Elasticsearch 集群.ElasticsearchTemplate 类已被弃用,因为它使用 TransportClient 访问 Elasticsearch,而 Elasticsearch 本身自 Elasticsearch 版本 7 起已被弃用.+ 用户应切换到 ElasticsearchRestTemplate 或 ReactiveElasticsearchTemplate.

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)

A see now that 3.2.0 M1 Spring Data Elasticsearch supports the HTTP client (https://docs.spring.io/spring-data/elasticsearch/docs/3.2.0.M1/reference/html/#reference)

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

According to the documentation (it could of course change because it's not final version so I will put it here):

众所周知的 TransportClient 自 Elasticsearch 7.0.0 起已弃用,预计将在 Elasticsearch 8.0 中移除.

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

2.1.高级 REST 客户端

2.1. High Level REST Client

Java 高级 REST 客户端提供了 TransportClient 的直接替代,因为它接受并返回完全相同的请求/响应对象,因此依赖于 Elasticsearch 核心项目.异步调用在客户端管理的线程池上进行操作,并且需要在请求完成时通知回调.

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 客户端

Example 49. High Level REST Client

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 的通信.他们正在使用传输客户端.

Currently Spring Data Elasticsearch doesn't support the communication by the REST API. They are using the transport client.

Spring Data Elasticsearch 有一个单独的分支(他和你一样需要它来用于 AWS),其中使用了 JEST 库并且通过 REST 进行通信:

There is separate fork of Spring Data Elasticsearch (the guy needed it for AWS the same as you) where the JEST library is used and communication is made by REST:

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

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

You will find the interesting discussion under the following ticked of Spring Data Elasticsearch:

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

根据 Elasticsearch 团队的声明,他们计划仅支持 ES 的 HTTP 通信,我认为 Spring Data Elasticseach 在未来需要迁移到 REST.

I think the Spring Data Elasticseach will need to migrate to REST on the future according to the statements from Elasticsearch team that they are planning to support only HTTP communication for ES.

希望有帮助.

这篇关于Elasticsearch Rest Client with Spring Data Elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆