查询索引量 @return count 统计数据 @return err 错误
()
| 396 | //@return count 统计数据 |
| 397 | //@return err 错误 |
| 398 | func (this *ElasticSearchClient) Count() (count int, err error) { |
| 399 | if !this.On { |
| 400 | err = errors.New("未启用ElasticSearch") |
| 401 | return |
| 402 | } |
| 403 | api := this.Host + this.Index + "/" + this.Type + "/_count" |
| 404 | if resp, errResp := this.get(api).Response(); errResp != nil { |
| 405 | err = errResp |
| 406 | } else { |
| 407 | b, _ := ioutil.ReadAll(resp.Body) |
| 408 | body := string(b) |
| 409 | if resp.StatusCode >= http.StatusMultipleChoices || resp.StatusCode < http.StatusOK { |
| 410 | err = errors.New(resp.Status + ";" + body) |
| 411 | } else { |
| 412 | var cnt ElasticSearchCount |
| 413 | if err = json.Unmarshal(b, &cnt); err == nil { |
| 414 | count = cnt.Count |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | return |
| 419 | } |
| 420 | |
| 421 | //删除索引 |
| 422 | //@param id 索引id |