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 elasticsearch

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how to use elasticsearch". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use elasticsearch.

Es.gopackage mainimport ("context"github.com/olivere/elastic"time") var (esUrl = "http://s10:19200" ctx = context.Background () client * elastic.Client) func init () {var err error client, err = elastic.NewClient (elastic.SetSniff (false), elastic.SetURL (esUrl)) Elastic.SetHealthcheckInterval (10*time.Second), elastic.SetMaxRetries (5) ) if err! = nil {panic (err.Error ())}} mysql.gopackage mainimport (_ "github.com/go-sql-driver/mysql"github.com/go-xorm/xorm") var (db * xorm.EngineGroup) func init () {conns: = [] string {"test:test@tcp (127.0.0.1 : 3306) / test "} var err error db Err = xorm.NewEngineGroup ("mysql" Conns) if err! = nil {panic (err.Error ())} db.ShowSQL (true) db.SetMaxIdleConns (5) db.SetMaxOpenConns (10)} model.gopackage mainimport ("encoding/json"time") type StudentAnswer struct {Id int64 `json: "id" `Qid int64 `json: "qid" `QuesType int `json: "ques_type" `ClassType int `json: "class_type" `LessonId int64 `json: "lesson_id" `ScheduleId int64 `json: "schedule_id" `IsFirstSubmit int `json: "is_first_submit" `IsRight int `json: "is_right" `StuAnswer string `json: "stu_answer" `Scores string `json: "scores" `StudentId int64 `json: "student_id" `CreatedAt time.Time `json: "created_at" `UpdatedAt time.Time `json: "updated_at" `} func (* StudentAnswer) TableName () string {return "student_answer"} func (sa * StudentAnswer) String () string {buf _: = json.Marshal (sa) return string (buf)} main.gopackage mainimport ("fmt"github.com/olivere/elastic"googo.io/goo/log"sync") var (MaxId = int64 (0) pageSize = 1000 index = "stu-answer" wg sync.WaitGroup ch = make (chan int64) 1000) data = make (chan [] StudentAnswer) func init () {/ / client.DeleteIndex (index) .Do (ctx) / / client.CreateIndex (index) .Do (ctx)} func main () {wg.Add (1) go func () {defer wg.Done () for { Rows: = getRows () fmt.Println (len (rows)) if rows = = nil | | len (rows) = = 0 {break} MaxId = rows [len (rows)-1] .ID data

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