I normally connect to an elastic server, save the connection to a global variable, and reuse it in my entire app.
var es *elasticsearch.Client
func elasticConnect() {
cfg := elasticsearch.Config{
CloudID: "my_cloud_id",
APIKey: "API_KEY"
}
var err error
es, err = elasticsearch.NewClient(cfg)
}
but sometimes I need to connect to another elastic instance and replace the global variable with the new one.
I want to know how close the old connection before making a new one (I looked in the documentation, but I couldn't find any method for closing the connections)