Elasticearch Rest Client with Spring Data Elasticsearch

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

Elasticearch Rest Client <here.

Simple, is it possible to use a REST client with Spring Data Elasticsearch?

In other words, does Spring Data Elasticsearch work with the Elasticearch Rest client?

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

+14
source share
3 answers

[February 2019 update]

Now we see 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, of course, can change, because this is not the final version, so I will publish it here):

Starting with Elasticsearch 7.0.0, the well-known TransportClient is deprecated and is expected to be removed in Elasticsearch 8.0.

2.1. High Level REST Client

The high-level Java REST client provides a direct replacement for TransportClient, as it receives and returns the same request / response objects and therefore depends on the main Elasticsearch project. Asynchronous calls are handled on the client pool of managed flows and require that the callback be notified when the request is completed.

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

[Original answer]

Spring Data Elasticsearch does not currently support communication through the REST API. They use a transport client.

There is a separate fork of Spring Data Elasticsearch (it is needed for AWS just like you), where the JEST library is used and communication is done using REST:

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

You will find an interesting discussion under the following Spring Data Elasticsearch checkbox:

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

I think that Spring Data Elasticseach in the future will have to switch to REST in accordance with the statements of the Elasticsearch team that they plan to support only HTTP communication for ES.

Hope it helps.

+21
source

I think the joker client for elasticsearch will serve your purpose. https://github.com/searchbox-io/Jest/tree/master/jest . Jest is an HTTP HTTP Rest client for ElasticSearch. It also has very good documentation and supports all queries in elasticsearch.

+1
source

I can not comment on the answer of Przemek Nowak above. If you do not want to wait while Spring Data ES 2.2.x will use the High Level Rest Client, then Spring Data Jest will save you.

According to their documentation, you will first disable Spring Data ES auto-configuration by default:

 @SpringBootApplication(exclude = { ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class }) 

And what are these - repositories will now use the Jest implementation. And if you want to use the ElasticsearchTemplate , make sure you have the ElasticsearchOperations interface of ElasticsearchOperations :

 private final ElasticsearchOperations esTemplate; 
0
source

Source: https://habr.com/ru/post/1269882/


All Articles