5
votes

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

1

1 Answers

8
votes

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;