本文摘自网络,作者,侵删。
连接es代码
$ cat loges.go
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v7"
)
func Loges(msg string, dateIndex string) {
addresses := []string{"http://10.20.9.105:9200"}
config := elasticsearch.Config{
Addresses: addresses,
Username: "elastic",
Password: "rxyn38#*",
CloudID: "",
APIKey: "",
}
// new client
es, err := elasticsearch.NewClient(config)
fmt.Println(err, "Error creating the client")
res, err := es.Info()
fmt.Println(err, "Error getting response")
// fmt.Println(res.String())
var buf bytes.Buffer
query := map[string]interface{}{
"query": map[string]interface{}{
"match": map[string]interface{}{
"msg": msg,
},
},
"highlight": map[string]interface{}{
"pre_tags": []string{"<font color='red'>"},
"post_tags": []string{"</font>"},
"fields": map[string]interface{}{
相关阅读 >>
手撸Golang Go与微服务 chatserver之4 内存泄漏
更多相关阅读请进入《Go》频道 >>

Go语言101
一个与时俱进的Go编程知识库。