1

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 ?

vipulk10
  • 117
  • 3
  • 15

3 Answers3

2

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.

MohamedSanaulla
  • 6,112
  • 5
  • 28
  • 45
  • I asked the question , since during one of our outages we realized that elasticsearch queries were executed normally (as per AWS console) , but our logs suggested the opposite. The time taken by es logged in by our services do not match what the aws console has . We are currently using restemplate with no connection pooling . – vipulk10 Nov 24 '19 at 15:25
  • Yes, you would have to include the time taken for the data to transport over the wire. But if the app interacting with ES is within the same VPC, then I dont think transport would be a problem. – MohamedSanaulla Nov 25 '19 at 07:56
  • Spring Data Elasticsearch supports the REST High Level Client since 3.2.0 (Spring Data Moore) which was released on September 30th, 2019. – P.J.Meisch Nov 25 '19 at 11:50
  • Thanks for answering , can we use high level rest client with aws manged es and not use spring data es altogether? – vipulk10 Nov 28 '19 at 06:45
  • Yes you can use. And we do that. Just ensure that if Managed ES is accessible from your app server. I.e you ensure the VPC / IP based security for Managed ES is configured correctly – MohamedSanaulla Nov 28 '19 at 07:11
  • have you experienced any performance improvement (faster response of search queries) while using es clients ?? – vipulk10 Nov 28 '19 at 11:11
  • I never used Spring data elastic search library. From the beginning I have been using transport client and now high level rest client. I don't have that much load to really comment about performance – MohamedSanaulla Nov 28 '19 at 16:01
2

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.

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
0

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

  • Sorry to say this, but this is wrong. Since version 3.2.0 (Spring Data Moore), Spring Data Elastcisearch *does* support the REST High Level Client - which is even mentioned in the answer that you linked. – P.J.Meisch Nov 25 '19 at 11:49
  • Since you are the so called 'Spring Data Elasticsearch project lead', I assume you know what you are talking about but, after having read the post and the official documentation (https://docs.spring.io/spring-data/elasticsearch/docs/3.2.x/reference/html/#reference) I must say the documentation confuses me quite a bit. Was trying to help but will think twice before making another statement with regards to Spring Data Elasticsearch. – Wim Van den Brande Nov 25 '19 at 12:15