Elasticsearch client API - elasticsearch

my question is about different Elasticsearch client APIs .. I wanted to migrate form Elasticsearch 6.2 to Elasticsearch 7
Currently i am using JEST Client library with elasticsearch v6.2, but its absolute now therefore with the upgrade i wanted to used client library provided by Elasticsearch, but number of libraries provided by Elasticsearch make me lost which one to use with v7.15
these are following ES client libraries
Java client :
deprecated in 7.9
https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.9/java-docs-index.html
REST clients: there are two REST clients
Low level REST client.
request marshalling and response un-marshalling is handled by the client
itself.
internally uses "Apache Http Async Client"
provide some basic domentation of rintailizing, request/response with java code
High Level client
deprecated in 7.15
it a layer on top of Low level client
performs request marshalling and response un-marshalling is handled by the client itself.
provides documentation with Java code
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.15/java-rest-high-document-index.html
so its look like Elasticsearch 7.15 can only use "Low level REST client" because other two clients " Java client " and "RES High Level clien" are deprecated.
and using REST LOW level client require to write lots of basic codes like marschalling /un-marshalling etc
is my understating correct ?
is there any other Elasticsearch client available /better to use to migrate to 7.15 ?

You are right, this is the only way for this version.
But starting with 7.16 version there is a new client ⇾ ElasticsearchClient handling marshalling and unmarshalling by itself (You pass class type as a parameter with calls) with already pretty neet documentation existing:
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/master/connecting.html

Related

Migration from Transport client to Java API client in ElasticSearch Springboot project

I am new to elasticsearch and I have a elasticsearch springboot project. We use docker to setup elasticsearch cluster and use springboot(backend),esclient to fetch data from elasticsearch. It is an old project and now I have the task of upgrading the cluster to it's latest version which is 8.x. Upon glancing upon the dependencies I saw that the project uses transport client but as per documentation the transport client is long deprecated and instead of that we were to use High level rest client client which was again deprecated in favor of JAVA Api client. So for the app to work I have to update the dependencies. I found the migration guide from transport client to high level rest client and the migration guide from high level rest client to java api client. I also gathered from the documentation that java api client and high level rest client do not have any relation and the transition to java api client can be done gradually)
Now my question is that
Suppose I upgrade from transport to java api client. Will this bring a whole lot of changes in my code as it is a really big project or is there a workaround in which I don't have to make that many changes in my code and I can work with elasticsearch version 8.
The need for the client upgrade didn't arise till now as we were still using 7.17.x and that was working fine till now but when I upgraded the cluster to version 8 and with that they are not providing transport client. My one approach is that I migrate to HLRC first and then gradually transition to JAVA api client.
Any help will be appreciated.
Regards

Partial Document update using Jest Client in elasticsearch

I am curious to know which client should I use for elasticSearch using java API. There are multiples clients like Jest, Transport, ElasticSearch clients. Also I have to perform CRUD operations on ES.
You should use the java high level rest client as its an official Elasticsearch java client(that supports all documents CRUD operations).
JEST is not official client and not available for latest ES version(not even 7.0 while 7.8 is released so not keeping pace with ES versions).
Transport client is used by high level client and is getting deprecated mention in this official doc.
Please read this thread for more info on all these clients and how they work internally.

save springboot output to elasticsearch engine

I have rest API through which I am sending and getting massages to the Kafka server using spring-boot. Now I want to save those messages to elasticsearch. How to do it can anyone help?
Actually this is a systematic job in which case, is somehow like setting up a database storage architecture.
TO BE SIMPLE AND SHORT:
First you need to decide which ES version you want to use, because there are some breaking changes between ES 2.x to 7.x. And those differences may affect the way you design the schema of your storage.
Assume you use latest 7.x ES, you will need to create index(es) where you want the data fetched from kafka to be stored into. Checkout https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
Later you have indexes created, you need to apply and learn some basic knowledge about ES high level rest client and low level rest client. The low level rest client enables you the basic connection to ES cluster via HTTP. And high level rest client apis give you sufficient ways to do ops like documents CRUD, search, aggregations for your data. You can easily find dependencies via maven and use them in your Spring Boot Application. Checkout https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high.html

Elastic search high/low rest client vs spring rest template

I am in a dilemma over to use spring's rest template or elasticsearch's own high/low rest client while searching in es . Does es client provide any advantage like HTTP connection pooling , performance while compared to spring rest template . Which of the two take less time in getting response from the server . Can some one please explain this ?
The biggest advantage of using Spring Data Elasticsearch is that you don't have to bother about the things like converting your requests/request bodies/responses from your POJO domain classes to and from the JSON needed by Elasticsearch. You just use the methods defined in the ElasticsearchOperations class which is implemented by the *Template classes.
Or going one abstraction layer up, use the Repository interfaces the all the Spring Data modules provide to store and search/retrieve your data.
Firstly, This is a very broad question. Not sure if it suits the SO guidelines.
But my two cents:
High Level Client uses Low Level client which does provide connection pooling
High Level client manages the marshalling and unmarshalling of the Elastisearch query body and response, so it might be easier to work using the APIs.
On the other hand, if you are familiar with the Elasticsearch querying by providing the JSON body then you might find it a bit difficult to translate between the JSON body and the Java classes used for creating the query (i.e when you are using Kibana console or other REST API tools)
I generally overcome this by logging the query generated by the Java API so that I can use it with Kibana console or other REST API tools.
Regarding which one is efficient- the library will not matter that much to affect the response times.
If you want to use Spring Reactive features and make use of WebClient, ES Libraries do provide support for Async search.
Update:
Please check the answer by Wim Van den Brande below. He has mentioned a very valid point of using Transport Client which has been deprecated over REST API.
So it would be interesting to see how RestTemplate or Spring Data ElasticSearch will update their API to replace TransportClient.
One important remark and caveat with regards to the usage of Spring Data Elasticsearch. Currently, Spring Data Elasticsearch doesn't support the communication by the High Level REST Client API. They are using the transport client. Please note, the TransportClient is deprecated as of Elasticsearch 7.0.0 and is expected to be removed in Elasticsearch 8.0!!!
FYI, this statement has been confirmed already by another post: Elasticsearch Rest Client with Spring Data Elasticsearch

ElasticSearch HTTP client vs Transport client

What is the best practice using ElasticSearch from Java?
For instance one can easily find documentation and examples for delete-by-query functionality using REST API.
This is not the case for Java Transport Client.
Where can I find usage examples for Java Transport Client ?
Does Java Transport Client cover whole ElasticSearch functionality like HTTP client via REST API?
The best practice of using Elasticsearch from Java: Follow This
Nexts:
You can follow the library : JEST
Yes, in maximum time, Java Transport Client cover whole ElasticSearch functionality like HTTP client via REST API
To complete #sunkuet02 answer:
As mentioned in documentation, the TransportClient is the preferred way if you're using java (performance, serialization, ...).
But the jar is quite heavy (with dependencies) and it requires that you use the same versions between client and server to work.
If you want a very lightweight client, there is a new Java REST client in Elastic 5.x.
I don't know the differences with Jest, but it's compatible with last Elastic 5.x versions (but not with previous versions) and it's developed by the Elastic team.
So it might be a good option to consider, according to your needs.

Resources