查询索引量 @return count 统计数据 @return err 错误
()
| 526 | //@return count 统计数据 |
| 527 | //@return err 错误 |
| 528 | func (this *ElasticSearchClient) Count() (count int, err error) { |
| 529 | if !this.On { |
| 530 | err = errors.New("未启用ElasticSearch") |
| 531 | return |
| 532 | } |
| 533 | api := this.Host + this.Index + "/" + this.Type + "/_count" |
| 534 | if resp, errResp := this.get(api).Response(); errResp != nil { |
| 535 | err = errResp |
| 536 | } else { |
| 537 | defer resp.Body.Close() |
| 538 | b, _ := ioutil.ReadAll(resp.Body) |
| 539 | body := string(b) |
| 540 | if resp.StatusCode >= http.StatusMultipleChoices || resp.StatusCode < http.StatusOK { |
| 541 | err = errors.New(resp.Status + ";" + body) |
| 542 | } else { |
| 543 | var cnt ElasticSearchCount |
| 544 | if err = json.Unmarshal(b, &cnt); err == nil { |
| 545 | count = cnt.Count |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | return |
| 550 | } |
| 551 | |
| 552 | // 删除书籍索引 |
| 553 | func (this *ElasticSearchClient) DeleteIndex(id int, isBook bool) (err error) { |