bi/engine/db/es.go
1340691923@qq.com ebbf4120bf 第一次提交
2022-01-26 16:40:50 +08:00

20 lines
473 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.NewClient(optList...)
return
}