易错点:
1,发送search请求时候,最好指定数量:
size是*int类型的数据(若为int 类型则初始值为0,拉取不到数据)
var size *int = new(int)
*size = 3000
// 发送搜索请求
req := esapi.SearchRequest{
Index: []string{index},
Body: strings.NewReader(string(query)),
Pretty: true, // 使得响应更易读(可选)
FilterPath: []string{"hits", "hits", "_source"}, // 过滤响应路径(可选)
Size: size,
}
若未设置size,源码中设置为10,只会拉取10条。此时不要惊奇拉取的数据为啥和你看到的数据不一样,考虑下是否是size限制的原因
if r.Size != nil {
params["size"] = strconv.FormatInt(int64(*r.Size), 10)
}