Skip to content

Commit

Permalink
es
Browse files Browse the repository at this point in the history
  • Loading branch information
blackroot committed Jul 9, 2021
1 parent 8b6f2d0 commit 24042e8
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions xelastic/olivere.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,33 @@ func InitElastic(conf *ElasticConf) {
panic(errors.WithStack(err))
}

_, _, err = client.Ping(conf.Url[0]).Do(context.TODO())
if err != nil {
panic(errors.WithStack(err))
for _, url := range conf.Url {
_, _, err = client.Ping(url).Do(context.TODO())
if err != nil {
panic(errors.WithStack(err))
}
}
})
}

func Stop() {
client.Stop()
}

func Index(index, typ string, doc interface{}) (*elastic.IndexResponse, error) {
rsp, err := client.Index().Index(index).Type(typ).BodyJson(doc).Do(context.TODO())
if err != nil {
return nil, errors.WithStack(err)
}

return rsp, nil
}

func Get(index, typ string) (*elastic.GetResult, error) {
result, err := client.Get().Index(index).Type(typ).Do(context.TODO())
if err != nil {
return nil, errors.WithStack(err)
}

return result, nil
}

0 comments on commit 24042e8

Please # to comment.