2.golang 操作elasticsearch-7


本文摘自网络,作者,侵删。

连接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的声明语法为什么是这样

Golang escape analyze

Go语言 for 循环

Go-const

精心整理!9个 python 实用案例分享

Golang | 一文带你快速入门context

什么是Golang中的interface

手撸Golang Go与微服务 chatserver之4 内存泄漏

Go语言多维数组

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...