High level rest client connection

Hello. Questions about maintaining the connection of "Elasticsearch-Rest-High-Level-Client" in Java.
RestClient.builder is created using a connection. But when i am using it on a 365-day server, do i have to connect and close after use? Or should I keep connected in a continuous state?

case 1.

  1. Starting the server
  2. Connect Elasticsearch to API required
  3. Disconnect
  4. Connect Elasticsearch to API required

case 2.

  1. Connect Elasticsearch with server startup
  2. Use API

What is right?

Case 2 is the correct one as clients create and use a pool of long running connections.

1 Like

Note that it might happen that your client is not connected anymore and that you should reconnect it in that case.

Have a look at Sniffer | Java REST Client [7.15] | Elastic as well.

1 Like

the Single instance of resthighlevelclient is appropriate?when i create one client instance to use and keep it long running,don't call its close method

Yes. A singleton is the best practice.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.