Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch Java High level REST Client - Singleton or one instance per user?

I am planning to use Java REST client in our application. Ours is a Java RESTful application running on Tomcat. We will have lot of search requests to ElasticSearch per second from different users. What is the best practice - To create a Singleton and use it application wide or create one instance per user?

If Singleton is the way to go, how many concurrent requests it can serve? Will that approach be scalable?

Thanks and Regards, Rajesh

like image 758
Rajesh Kumar Avatar asked Sep 22 '17 05:09

Rajesh Kumar


People also ask

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.

Is RestHighLevelClient thread safe?

Both RestClient and RestHighLevelClient are thread safe. As per documentation you should have only one object per application.

How do I use RestHighLevelClient?

Search Documents First, create a SearchRequest passing the index name as the argument. After that, SearchSourceBuilder needs to be created. Add to it the query you want to execute. Lastly, execute the SearchRequest through the REST client.

What is Elasticsearch client?

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Since its release in 2010, Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.


1 Answers

Both RestClient and RestHighLevelClient are thread safe. As per documentation you should have only one object per application.

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_changing_the_client_8217_s_initialization_code.html

like image 191
mkalsi Avatar answered Nov 14 '22 08:11

mkalsi