Skip to content

Instantly share code, notes, and snippets.

@MedUnes
Created July 14, 2025 13:51
Show Gist options
  • Save MedUnes/2aa5e6c2f7b87dd4e0d22c7180a7f2d9 to your computer and use it in GitHub Desktop.
Save MedUnes/2aa5e6c2f7b87dd4e0d22c7180a7f2d9 to your computer and use it in GitHub Desktop.
createElasticClient.go
/**
* Create an elasticearch instance
**/
package main
import (
"crypto/tls"
"log"
"net/http"
"github.com/olivere/elastic/v7"
"github.com/spf13/viper"
)
func createElasticClient() *elastic.Client {
client, err := elastic.NewClient(
elastic.SetURL(viper.GetString("ELASTIC_ENDPOINT")),
elastic.SetBasicAuth(
viper.GetString("ELASTIC_USER"),
viper.GetString("ELASTIC_PASSWORD"),
),
elastic.SetHttpClient(&http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}),
elastic.SetSniff(false),
)
if err != nil {
log.Fatalf("Error creating client: %v", err)
}
return client
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment