package elastic import ( "bytes" "context" "encoding/json" "fmt" esv7 "github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v7/esapi" "io/ioutil" "log" "math" "strings" ) type EsSearch struct {} var esClient *esv7.Client //初始化db func InitDb() { var err error cfg := esv7.Config{ Addresses: []string{ "搜索接口地址", }, Username: "用户名", Password: "密码", } client, err := esv7.NewClient(cfg) if err != nil { panic(err) } esClient = client } func NewEsClient() *EsSearch{ return &EsSearch{} } //使用sql语句查询 func(this *EsSearch) SqlQuery(sql string) string { query:=map[string]interface{}{ "query":sql, } jsonBody , _ := json.Marshal(query) req := esapi.SQLQueryRequest{ Body: bytes.NewReader(jsonBody), } r
golang elasticsearch v7版本最全接口封装
于 2023-12-21 18:22:06 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)