I'm using Golang & elastic client.
Bellow is my client creation logic:
if client, err := elastic.NewClient(elastic.SetURL(ElasticsearchURL)); err != nil {
// Handle error
logger.Error.Println(err)
return nil
} else {
return client
}
Whats the correct approach to:
- keep the client object singleton across the application?
- create and close the clients for each request?
I am kind of confused between counterintuitive answers in below links:
- where-to-close-an-elasticsearch-client-connection- suggests one connection per app
- how-many-transport-clients-can-a-elasticsearch-cluster-have - suggests one connection per app
- elasticsearch-how-to-query-for-number-of-connections -- kind of indicates connections quickly die after serving a request