使用Java高级Rest客户端进行Spring数据弹性搜索 [英] Spring data elastic search with Java high level rest client

查看:118
本文介绍了使用Java高级Rest客户端进行Spring数据弹性搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Elastic搜索的初学者,并且正在寻找将Elastic Search与Spring Boot集成的最佳方法.

I am a beginner in Elastic search and looking for best way to integrate elastic search with Spring boot.

我不确定要使用以下哪个:-

I am not sure which of the following to use:-

  • 春季数据弹性搜索

  • Spring data elastic search

JEST

谢谢

推荐答案

这取决于您要如何与ES交互.

It depends on how you want to interact with ES.

如果您想在Elasticsearch之上使用ORM对文档执行CRUD操作,则可以使用Spring Data Elasticsearch.但是请注意,Spring Data ES落后于最新的ES版本,因此根据您的ES版本,集成Spring Data ES(通过Spring Boot)可能会更加困难.

If you want to use an ORM on top of Elasticsearch to perform CRUD operations on documents, then Spring Data Elasticsearch is the way to go. Beware, though, Spring Data ES lags a bit behind the latest ES releases, so depending on your ES version, it might be more difficult to integrate Spring Data ES (via Spring Boot).

另外两个是更通用的客户端,这些客户端使您可以使用ES进行几乎所有操作.

The other two are more general purpose clients, which allow you to do pretty much anything with ES.

JEST是一个不错的选择,并且由于Elasticsearch缺乏真正好的REST客户端,很长一段时间以来,它一直是我的最爱之一.

JEST is a good choice and has been one of my favorite for a long time since Elasticsearch lacked a real good REST client.

随着Elastic投入更多的精力,Java高级REST客户端越来越受关注(因为传输客户端正在消失).这个最大的优点是它是Elastic支持的官方REST客户端,并且与请求/响应DSL很好地集成在一起,而JEST则没有.

The Java High-Level REST client is getting more traction as Elastic puts more effort into it (since the transport client is doing to disappear). The big advantage of this one is that it is the official REST client supported by Elastic and offers a good integration with the request/response DSL, which JEST doesn't.

更新

要将REST客户端与Spring Boot集成在一起,您可以像其他任何依赖项一样进行操作,这样,创建一个配置bean,然后在需要的地方自动关联该依赖项:

To integrate the REST client with Spring Boot, you can do it like any other dependency, like this, create a configuration bean and then autowire the dependency wherever you need:

/** Configuration Bean */
@Configuration
public class ElasticsearchConfig {

    @Value("${elasticsearch.host}")
    private String host;

    @Value("${elasticsearch.port}")
    private int port;

    @Bean
    public RestClient restClient() {
        return RestClient.builder(new HttpHost(host, port)).build();
    }
}

// use the dependency in your other components/services, using dependency injection
@Autowired
private RestClient restClient;

这篇关于使用Java高级Rest客户端进行Spring数据弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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