MCPcopy Index your code
hub / github.com/TruthHun/DocHub / BuildIndexByBuck

Method BuildIndexByBuck

models/ElasticSearchModel.go:343–367  ·  view source on GitHub ↗

通过bulk,批量创建/更新索引

(data []ElasticSearchData)

Source from the content-addressed store, hash-verified

341
342//通过bulk,批量创建/更新索引
343func (this *ElasticSearchClient) BuildIndexByBuck(data []ElasticSearchData) (err error) {
344 var bodySlice []string
345 if len(data) > 0 {
346 for _, item := range data {
347 action := fmt.Sprintf(`{"index":{"_index":"%v","_type":"%v","_id":%v}}`, this.Index, this.Type, item.Id)
348 bodySlice = append(bodySlice, action)
349 bodySlice = append(bodySlice, util.InterfaceToJson(item))
350 }
351 api := this.Host + "_bulk"
352 body := strings.Join(bodySlice, "\n") + "\n"
353 if helper.Debug {
354 helper.Logger.Info("批量更新索引请求体")
355 helper.Logger.Info(body)
356 }
357 if resp, errResp := this.post(api).Body(body).Response(); errResp != nil {
358 err = errResp
359 } else {
360 if resp.StatusCode >= http.StatusMultipleChoices || resp.StatusCode < http.StatusOK {
361 b, _ := ioutil.ReadAll(resp.Body)
362 err = errors.New(resp.Status + ";" + string(b))
363 }
364 }
365 }
366 return
367}
368
369//创建索引
370func (this *ElasticSearchClient) BuildIndex(es ElasticSearchData) (err error) {

Callers 1

RebuildAllIndexMethod · 0.95

Calls 2

postMethod · 0.95
ResponseMethod · 0.80

Tested by

no test coverage detected