service/library/elasticsearchdb/client.go

23 lines
533 B
Go

package elasticsearchdb
import (
"service/bizcommon/util"
"service/library/configcenter"
"service/library/logger"
"github.com/olivere/elastic/v7"
)
func NewElasticSearchClient(cfg *configcenter.ElasticSearchConfig) (client *elastic.Client, err error) {
client, err = elastic.NewClient(
elastic.SetURL(cfg.Uri),
elastic.SetSniff(cfg.Sniff),
elastic.SetBasicAuth(cfg.Username, cfg.Password),
)
if err != nil {
logger.Error("NewElasticSearchClient fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return
}
return
}