Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch-rest-high-level-client vs elasticsearch-rest-client

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?

like image 231
Dev Chauhan Avatar asked Jun 12 '20 08:06

Dev Chauhan


People also ask

What is 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.

What is Java high level REST client?

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.

What is transport client Elasticsearch?

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.

What is REST client builder?

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() .


1 Answers

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 Javadoc
  • Low Level Rest Client Javadoc

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:

  • Avoid developers to re-write code or in other words maintainability and readability of code.
  • Helps developers understand and co-relate with ES's API usage like that of using Kibana
  • If any of xpack features are to be used as well(graph or ml), High Level Client API has the client code available which could be used without hassle of rewriting everything using low level API.

Below sample examples can help I guess:

Example 1: Get a particular document

With High Level Rest Client:

GetRequest getRequest = new GetRequest("posts", "1");   

With Low Level Rest Client:

Request request = new Request("GET", "/posts/1");

Example 2: Search API

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

Example 3: Analyze text:

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!

like image 155
Kamal Avatar answered Sep 28 '22 00:09

Kamal