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 }