I'm new to Elastic search. Started building a Spring boot application with Elastic search.
Using the latest ES version "elasticsearch-7.7.1" and for integration, I'm using below maven dependency:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.7.1</version>
</dependency>
I've faced issue in application startup, fixed by adding below dependency:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.7.1</version>
</dependency>
Can anyone explain why elasticsearch-rest-client
needed and how it differs from 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.
The Java High-Level REST is built on top of the low-level client described above. It provides different API specific methods that accept objects as arguments and returns a response as an object, hence taking care of the request marshaling and response unmarshalling.
The transport client allows to create a client that is not part of the cluster, but simply connects to one or more nodes directly by adding their respective addresses using addTransportAddress(org. elasticsearch. common.
The RestClientBuilder is a Configurable class as defined by JAX-RS. This allows a user to register providers, implementation specific configuration. Implementations are expected to implement this class and provide the instance via the mechanism in RestClientBuilderResolver. instance() .
In the link it mentions below:
Java Low Level REST Client: the official low-level client for Elasticsearch. It allows to communicate with an Elasticsearch cluster through http. Leaves requests marshalling and responses un-marshalling to users. It is compatible with all Elasticsearch versions.
Java High Level REST Client: the official high-level client for Elasticsearch. Based on the low-level client, it exposes API specific methods and takes care of requests marshalling and responses un-marshalling.
Best way to understand more on this is to read the javadocs for which below are the links respectively
High Level Rest Client
makes use of Low Level Rest Client
which I believe, means, it extends classes and interfaces of Low Level Rest Client
.
Advantages of using High Level
over Low Level
are:
Below sample examples can help I guess:
With High Level Rest Client:
GetRequest getRequest = new GetRequest("posts", "1");
With Low Level Rest Client:
Request request = new Request("GET", "/posts/1");
With High Level Rest Client:
SearchRequest searchRequest = new SearchRequest("posts");
You can refer to this link
With Low Level Rest Client:
You would need to make use of Request
and Response
classes(low level) and using appropriate end-point
Request request = new Request("GET", "/posts/_search");
With High Level Rest Clent:
Make use of AnalyzeRequest class
With Low Level Rest Client:
Use again Request
and Response
class
Basically working on High Level Rest Client
is like working on Elasticsearch's API layer (which indirectly works via HTTP packages) while Low Level
is purely working on HTTP i.e. Request and Response models i.e. a higher abstraction.
Hope that helps!
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