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
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.
Both RestClient and RestHighLevelClient are thread safe. As per documentation you should have only one object per application.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With