0%

Elastic数据库驱动

配置

1
2
3
4
5
elastic:
addresses:
- http://localhost:9200
username:
password:

初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// elasticsearch7 "github.com/elastic/go-elasticsearch/v7"

// ES es7客户端
var ES *elasticsearch7.Client

// initES 初始化es
func initES(cfg *configs.Config) {
defer wg.Done()
if cfg == nil || len(cfg.Elastic.Addresses) == 0 {
return
}

var err error
if ES, err = elasticsearch7.NewClient(elasticsearch7.Config{
Addresses: cfg.Elastic.Addresses,
Username: cfg.Elastic.Username,
Password: cfg.Elastic.Password,
}); err != nil {
tools.Log.Error(ctx, "[initES] err = %v", err)
}
}