package es import ( "context" "fmt" "git.168cad.top/zhengqiuyun/rym-util/conf" "git.168cad.top/zhengqiuyun/rym-util/exception" "git.168cad.top/zhengqiuyun/rym-util/log" "github.com/olivere/elastic/v7" _log "log" "os" "testing" ) func init() { conf.Es = conf.EsConf{ ServerHost: "to-chengdu-office.168cad.top", ServerPort: 50037, } } func TestName(t *testing.T) { host := "http://to-chengdu-office.168cad.top:50037" var err error errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags) client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetErrorLog(errorLog), elastic.SetURL(host)) if err != nil { exception.ThrowsErrS(fmt.Sprintf("ES连接失败:%s", err.Error())) } info, code, err := client.Ping(host).Do(context.Background()) if err != nil { panic(err) } log.Info(fmt.Sprintf("Elasticsearch connect %d", code)) log.Info(fmt.Sprintf("Elasticsearch version %s", info.Version.Number)) }