service/library/elasticsearchdb/client.go

23 lines
533 B
Go
Raw Normal View History

2024-05-11 10:22:32 +08:00
package elasticsearchdb
2024-05-10 15:40:09 +08:00
import (
2024-05-10 18:11:36 +08:00
"service/bizcommon/util"
"service/library/configcenter"
"service/library/logger"
2024-05-10 15:40:09 +08:00
"github.com/olivere/elastic/v7"
)
2024-05-11 19:29:33 +08:00
func NewElasticSearchClient(cfg *configcenter.ElasticSearchConfig) (client *elastic.Client, err error) {
2024-05-11 10:22:32 +08:00
client, err = elastic.NewClient(
2024-05-10 18:11:36 +08:00
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
2024-05-10 15:40:09 +08:00
}