// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package elastic import ( elastic "gopkg.in/olivere/elastic.v5" ) // elastic客户端 var client *elastic.Client // Setup 建立elasitc连接 func Setup(addrs []string, sniff bool) { var err error client, err = elastic.NewClient(elastic.SetURL(addrs...), elastic.SetSniff(sniff), elastic.SetTraceLog(new(TraceLog)), elastic.SetInfoLog(new(InfoLog)), elastic.SetErrorLog(new(ErrorLog))) if err != nil { panic(err) } } // Client 获取elastic客户端 func Client() *elastic.Client { return client } // Stop 停止elastic客户端运行 func Stop() { if client != nil { client.Stop() } }