service/library/elastic_search/client.go

25 lines
557 B
Go

package elasticsearch
import (
"service/bizcommon/util"
"service/library/configcenter"
"service/library/logger"
"github.com/olivere/elastic/v7"
)
var defaultElasticSearchClient *elastic.Client
func Init(cfg *configcenter.ElasticSearchConfig) (err error) {
defaultElasticSearchClient, 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
}