bi/engine/db/es.go
1340691923@qq.com 68341adf80 优化
2022-02-17 17:22:02 +08:00

20 lines
479 B
Go

package db
import "github.com/olivere/elastic"
var EsClient *elastic.Client
func NewEsClient(address []string, username, password string) (esClient *elastic.Client, err error) {
optList := []elastic.ClientOptionFunc{elastic.SetSniff(false)}
optList = append(optList, elastic.SetURL(address...))
if username != "" || password != "" {
optList = append(optList, elastic.SetBasicAuth(username, password))
}
esClient, err = elastic.NewSimpleClient(optList...)
return
}