Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use golang in elasticsearch3

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use golang in elasticsearch3. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Package mainimport ("context", "fmt", "github.com/olivere/elastic", "reflect"time") var (esUrl = "http://s100:9200" ctx = context.Background ()) type User struct {Name string `json:" name "`Age int `json:" age "`} func main () {/ / linked server client Err: = elastic.NewClient (elastic.SetSniff (false), elastic.SetURL (esUrl), elastic.SetHealthcheckInterval (10*time.Second), elastic.SetMaxRetries (5),) if err! = nil {panic (err.Error ())} / / get basic information info, code Err: = client.Ping (esUrl) .Do (ctx) if err! = nil {panic (err.Error ())} fmt.Println ("> es-info > >", info.Version.Number, code) client.Delete () .Index ("user") / / whether index exists exists Err: = client.IndexExists ("user") .Do (ctx) if err! = nil {panic (err.Error ())} fmt.Println ("> index-exists > >", exists) / / create index if! exists {rst Err: = client.CreateIndex ("user") .Do (ctx) if err! = nil {panic (err.Error ())} fmt.Println ("> index-index > >", rst.Index)} / / batch add for I: = 1 I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report