daShangDao_centerBook/util/esClient/esClient.go
2026-02-28 14:27:33 +08:00

34 lines
645 B
Go

package esClient
import (
"github.com/elastic/go-elasticsearch/v8"
)
type ESClient struct {
Client *elasticsearch.Client
}
func NewESClient(addresses []string, username, password string) (*ESClient, error) {
cfg := elasticsearch.Config{
Addresses: addresses,
Username: username,
Password: password,
}
client, err := elasticsearch.NewClient(cfg)
if err != nil {
return nil, err
}
return &ESClient{
Client: client,
}, nil
}
// Close 关闭 Elasticsearch 客户端连接
func (e *ESClient) Close() error {
// 目前 elasticsearch 客户端没有提供 Close 方法
// 这里可以添加一些清理工作
return nil
}