golang操作es批量索引数据Bulk

更新时间:2023-06-26 16:08:37 阅读: 评论:0

golang操作es批量索引数据Bulk 减少开销提⾼效率现有130万条数据⼀条⼀条索引的话需要不停的跑需要两天左右如果使⽤bulk 五分钟就完事⼉了
func IndexPrice() {
es := tool.ES{cad三视图
Index: "financials.us.gama",
感恩老师的朗诵稿Type:  "esstockprice",
}
养生秘方
var MaxId int
MaxId = 0
var price *model.PriceRecord
团员推优演讲稿
// 每次取两万条数据索引两万条记录最⼤id 下⼀次根据maxid查询
for {
bulkRequest := tool.Client.Bulk()
// 每次只取2万条数据
priceList := price.GetPrice2(MaxId)
关于学校的作文if len(priceList) == 0 {
break
}
var upDateList []int
for _, i := range priceList {
upDateList = append(upDateList, i.ID)
if i.ID > MaxId {
MaxId = i.ID
}
id := i.Symbol + "_" + i.DateTime
var esPrice *ESPrice
esPrice = &ESPrice{
ShortName:    i.Symbol,
TradeDate:    i.DateTime,
StockPriceId: id,
IsTradeDate:  1,
Open:        i.Open,
广播稿100字左右
Clo:        i.Clo,
Volume:      i.Volume,
High:        i.High,
Low:          i.Low,
}
req := elastic.NewBulkIndexRequest().
Index(es.Index).
Type(es.Type).
Id(id).
Doc(esPrice)
bulkRequest = bulkRequest.Add(req)
}
bulkRespon, err := bulkRequest.Do(context.Background())
灰色英文怎么读if err != nil {
fmt.Println(err)棚车
}el{
// 索引成功就修改数据库状态 is_index = 1
if !price.UpdatePriceList(upDateList){
fmt.Println("更新数据库状态错误")
}
}
fmt.Println("耗时:",bulkRespon.Took, "索引了:",len(bulkRespon.Items))
}
}

本文发布于:2023-06-26 16:08:37,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1044870.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数据   状态   数据库   效率   开销   减少
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图