go 连接es初始化

1、安装包

#https://github.com/olivere/elastic
#这里我用的是v6版本,所有安装v6的
go get github.com/olivere/elastic

2、初始化连接

const (
	ES_HOST = "http://127.0.0.1:9200/"
)
var EsClient *elastic.Client

func Es_inti() {
	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
	log.Println("开始连接es")
	EsClient,err:=elastic.NewClient(elastic.SetInfoLog(errorlog),elastic.SetSniff(false),elastic.SetURL(conf.ES_HOST))
	if err!=nil{
		log.Println("连接失败!!!",err)
		return
	}

	log.Println("连接es成功!!!")
}
posted on 2022-08-05 15:32  每天进步一点点点点点  阅读(471)  评论(0)    收藏  举报