2.golang 操作elasticsearch-7


当前第2页 返回上一页

                                "title": map[string]interface{}{},

                        },

                },

        }

        if err := json.NewEncoder(&buf).Encode(query); err != nil {

                fmt.Println(err, "Error encoding query")

        }

        // Perform the search request.

        res, err = es.Search(

                es.Search.WithContext(context.Background()),

                es.Search.WithIndex(dateIndex),

                es.Search.WithBody(&buf),

                es.Search.WithTrackTotalHits(true),

                es.Search.WithPretty(),

        )

        if err != nil {

                fmt.Println(err, "Error getting response")

        }

        defer res.Body.Close()

        // return res.String()

        fmt.Println(res.String())

}

main代码

$ cat main.go

package main

import (

        "flag"

)

var (

        msg      string

        dateIndex string

)

func init() {

        flag.StringVar(&msg, "msg", "检验是否满足xx条件", "输入要匹配的内容")

        flag.StringVar(&dateIndex, "dateIndex", "log_prod-2021-03-11", "输入要搜索的索引")

}

func main() {

        flag.Parse()

        Loges(msg, dateIndex)

}

编译构建

go build -o loges.exe .\main.go .\loges.go

执行

./loges.exe -msg "校验是否满足xx条件" -dateIndex "log_prod-2021-03-17"


本文来自:简书

感谢作者:haodevops

查看原文:2.golang 操作elasticsearch-7

返回前面的内容

相关阅读 >>

Golang recover后怎么返回

Go设计模式之工厂模式浅谈

手撸Golang Go与微服务 saga模式之3

Golang判断是否是素数的方法

Golang 中const是什么

Golang不用指针可以吗

Golang中main中panic和后续panic处理,以及新开协程的影响

Go 将数组按指定大小分隔

19 Golang包以及Go mod

Golang 1.11 module 做项目版本管理

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




打赏

取消

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

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

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

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

评论

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