1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package main
import ( "context" "fmt"
"github.com/olivere/elastic" )
var client *elastic.Client var host = "http://x.x.x.x:29200/"
func init() { fmt.Println("开始初始化")
var err error
client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(host)) if err != nil { panic(err) }
info, _, err := client.Ping(host).Do(context.Background()) if err != nil { panic(err) } fmt.Printf("version %s\n", info.Version.Number) fmt.Println("初始化完成,连接成功") }
|