Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data elastic search with Java high level rest client [closed]

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

  • Java high level rest client

Thanks

like image 570
Puja Barad Avatar asked Mar 08 '18 12:03

Puja Barad


People also ask

What is Elasticsearch rest high level client?

High level REST client that wraps an instance of the low level RestClient and allows to build requests and read responses. The RestClient instance is internally built based on the provided RestClientBuilder and it gets closed automatically when closing the RestHighLevelClient instance that wraps it.

What is Java high level REST client?

The Java High-Level REST client works on top of the Java Low-Level REST client. Its main goal is to expose API specific methods, that accept request objects as an argument and return response objects, so that request marshalling and response un-marshalling is handled by the client itself.

Does spring data support Elasticsearch?

Spring Data Elasticsearch provides a simple interface to perform these operations on Elasticsearch as an alternative to using the REST APIs directly.

Is Elasticsearch reactive?

Spring Data Elasticsearch comes with three interfaces that supports reactive operations: ReactiveRepository , ReactiveCrudRepository that adds save/update operations, and ReactiveSortingRepository offering some methods with sorting.


1 Answers

It depends on how you want to interact with ES.

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).

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

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

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.

UPDATE

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;
like image 180
Val Avatar answered Sep 22 '22 22:09

Val