Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Spring Data with RestHighLevelClient

I don't understand the relationship between the High Level REST CLient (which replaces the Transport Client) and Spring Data Elasticsearch.

There are tutorials (https://www.baeldung.com/spring-data-elasticsearch-tutorial) showing how to make JPA-style queries with auto-implemented methods like getSomethingById(). They utilize this interface:

public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {

But ElasticsearchRepository seems to require a @Configuration-Class with an ElasticsearchTemplate-Bean and that requires the TransportClient. As far as I have tried out, there is no way of replacing it with the High/Low Level Java Rest Clients, no?

So if I want to use the newest official Client, there is no JPA-goodness for me?

like image 766
Phil Avatar asked Aug 15 '18 04:08

Phil


People also ask

Why ElasticsearchTemplate is deprecated?

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 .

How do I use RestHighLevelClient?

Search Documents First, create a SearchRequest passing the index name as the argument. After that, SearchSourceBuilder needs to be created. Add to it the query you want to execute. Lastly, execute the SearchRequest through the REST client.

What is RestHighLevelClient?

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.


2 Answers

There's an open issue regarding this in the Spring Data ES repo: https://jira.spring.io/browse/DATAES-407

like image 86
Val Avatar answered Sep 17 '22 06:09

Val


spring-data-elasticsearch 3.2.0, now available as M2 contains the code to use the RestClient.

See my answer to this question: What Elasticsearch client does Spring-Data-Elasticsearch use under the hood? for how to set it up

like image 41
P.J.Meisch Avatar answered Sep 17 '22 06:09

P.J.Meisch