| 12345678910111213141516171819202122232425262728293031 |
- package es
- import (
- "crypto/tls"
- "fmt"
- "net"
- "net/http"
- "time"
- "github.com/elastic/go-elasticsearch/v8"
- )
- func GetEsClient(esHost string, esPort int64, esUsername, esPassword string) (*elasticsearch.Client, error) {
- cfg := elasticsearch.Config{
- Addresses: []string{
- fmt.Sprintf("http://%s:%d", esHost, esPort),
- },
- Username: esUsername,
- Password: esPassword,
- Transport: &http.Transport{
- MaxIdleConnsPerHost: 10,
- ResponseHeaderTimeout: time.Second,
- DialContext: (&net.Dialer{Timeout: time.Second}).DialContext,
- TLSClientConfig: &tls.Config{
- MinVersion: tls.VersionTLS12,
- },
- },
- }
- return elasticsearch.NewClient(cfg)
- }
|