bi/engine/db/es.go

20 lines
479 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))
}
2022-02-17 17:22:02 +08:00
esClient, err = elastic.NewSimpleClient(optList...)
2022-01-26 16:40:50 +08:00
return
}