bi/engine/db/es.go

20 lines
473 B
Go
Raw Normal View History

2022-01-26 16:40:50 +08:00
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
}