Delay for elasticsearch connection


#1

Hi.
I have a java class that includes many methods. each method first connect to elasticsearch and does operations on indices and finally close the connection.
When the program is running i have a long delay for connecting to elasticsearch for every methodes.I want to know that how solve this problem. (why this problem is occurred, too)
Please help me.


(David Pilato) #2

What kind of client are you using to connect to elasticsearch?

Transport? Rest?


#3

Transport


(David Pilato) #4

Just create one instance of the Transport client for the whole application and reuse that instance any time you need. It's thread safe.


#5

thanks dadoonet.
But in my application these methods should be connect to elasticserach simultaneously and do operations on indices, that's mean multi threads connect to elasticsearch at the same time and i have long delay for connecting to elasticsearch for every thread.
What can be done to solve this problem?


(David Pilato) #6

What can be done to solve this problem?

Follow my advice.

Share your Transport Client within your application please.
You don't need to create multiple instances.


#7

Should i use a singleton instance of transport client for multiple threads? Please exactly help me how share transport client within my application by an example?
thanks.


(David Pilato) #8

Should i use a singleton instance of transport client for multiple threads?

Yes.


(system) #9

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