删除书籍索引
(id int, isBook bool)
| 551 | |
| 552 | // 删除书籍索引 |
| 553 | func (this *ElasticSearchClient) DeleteIndex(id int, isBook bool) (err error) { |
| 554 | if !this.On { |
| 555 | return |
| 556 | } |
| 557 | |
| 558 | _id := strconv.Itoa(id) |
| 559 | idStr := "doc_" + _id |
| 560 | if isBook { |
| 561 | idStr = "book_" + _id |
| 562 | } |
| 563 | |
| 564 | // 不管是书籍id还是文档id,常规删除操作API如下: |
| 565 | api := this.Host + this.Index + "/" + this.Type + "/" + idStr |
| 566 | |
| 567 | if err = utils.HandleResponse(this.delete(api).Response()); err != nil { |
| 568 | beego.Info(api) |
| 569 | beego.Error(err.Error()) |
| 570 | } |
| 571 | |
| 572 | if isBook { //如果是删除书籍的索引,则接下来删除书籍所对应的文档的索引。使用条件查询的方式进行删除操作 |
| 573 | api = this.Host + this.Index + "/_delete_by_query" |
| 574 | body := fmt.Sprintf(`{"query":{"term":{ "book_id":%v}}}`, id) |
| 575 | err = utils.HandleResponse(this.post(api).Body(body).Response()) |
| 576 | if err != nil { |
| 577 | beego.Info(api) |
| 578 | beego.Error(err.Error()) |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return |
| 583 | } |
| 584 | |
| 585 | //检验es服务能否连通 |
| 586 | func (this *ElasticSearchClient) ping() error { |
no test coverage detected