I'm new to Elastic search. We are building a Spring boot application with Elastic search.
For integrating my Spring boot application either we can use elasticsearch-rest-high-level-client
or spring-boot-starter-data-elasticsearch
.
Can anyone please elaborate on which option would be overall better and why?
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.
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.
Spring Data Elasticsearch provides a simple interface to perform these operations on Elasticsearch as an alternative to using the REST APIs directly.
Spring Data helps avoid boilerplate code. For example, if we define a repository interface that extends the ElasticsearchRepository interface that Spring Data Elasticsearch provides, CRUD operations for the corresponding document class will become available by default.
spring-boot-starter-data-elasticsearch
internally can use the transport(soon to be deprecated in ES 8.X)
or rest-high-level-client
Please refer elasticsearch client section for more information and how to configure them.
And from the same link :
Spring data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster. Although the Elasticsearch Client can be used to work with the cluster, applications using Spring Data Elasticsearch normally use the higher level abstractions of Elasticsearch Operations and Elasticsearch Repositories.
Bottom line is that you can directly use rest-high-level
client in your spring boot application but if you want more abstraction then you can use the spring-boot-starter-data-elasticsearch
dependency and use its method which provides more abstraction although internally it would use the client offered by Elasticsearch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With