What is the correct way of handling client in Elasticsearch?


(Jayaprakash Narayanan) #1

is creating and closing client in each functions the correct way ? Let's take we have 3 functions createIndex(), createMapping(), importDataToES().

           initClientObject()
                     createIndex()
           client.close()
           //method 2
           initClientObject()
                     createMapping()
           client.close()
           //method3
           initClientObject()
                     importDataToES()
           client.close()

(David Pilato) #2

No. Create one single client instance for your VM. It's threadsafe.


(Jayaprakash Narayanan) #3

Will there be a performance issue, if we keep the connection open for long time? Because in this case can create connection(i.e client) when we start the application and can destroy it when we shutdown the application.


(David Pilato) #4

People are doing that for years now with the Java client.

Yes, create a client when the application starts and close it when the application stops.


(Jayaprakash Narayanan) #5

Thanks for the reply.. Let us check


(system) #6