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{}{

阅读剩余部分

相关阅读 >>

Go-carbon1.2.4发布了!新增系列时间比较方法

Go调优神器trace介绍

Golang位运算符

docker 概述

Go - httpclient 常用操作

知乎从python转为Go,是不是代表Go比python好?

bash getopt 使用

Golang的反射reflect深入理解和示例

安装Go语言支持及Gogs版本管理工具

Go 语言 协程和管道讲解

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




打赏

取消

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

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

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

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

评论

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