Created
July 14, 2025 13:51
-
-
Save MedUnes/2aa5e6c2f7b87dd4e0d22c7180a7f2d9 to your computer and use it in GitHub Desktop.
createElasticClient.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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