javaspring-bootmavenelasticsearch-high-level-restclientelasticsearch-rest-client

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?


Solution

  • 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:

    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!