创建索引
(es ElasticSearchData)
| 368 | |
| 369 | //创建索引 |
| 370 | func (this *ElasticSearchClient) BuildIndex(es ElasticSearchData) (err error) { |
| 371 | var ( |
| 372 | js []byte |
| 373 | resp *http.Response |
| 374 | ) |
| 375 | if !this.On { |
| 376 | return |
| 377 | } |
| 378 | if helper.Debug { |
| 379 | beego.Info("创建索引--------start--------") |
| 380 | fmt.Printf("%+v\n", es) |
| 381 | beego.Info("创建索引-------- end --------") |
| 382 | } |
| 383 | api := this.Host + this.Index + "/" + this.Type + "/" + strconv.Itoa(es.Id) |
| 384 | if js, err = json.Marshal(es); err == nil { |
| 385 | if resp, err = this.post(api).Body(js).Response(); err == nil { |
| 386 | if resp.StatusCode >= 300 || resp.StatusCode < 200 { |
| 387 | b, _ := ioutil.ReadAll(resp.Body) |
| 388 | err = errors.New("生成索引失败:" + resp.Status + ";" + string(b)) |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | return |
| 393 | } |
| 394 | |
| 395 | //查询索引量 |
| 396 | //@return count 统计数据 |
no test coverage detected