设置书籍的公有和私有,需要根据文档同时更新文档的公有和私有
(bookId int, public bool)
| 435 | |
| 436 | // 设置书籍的公有和私有,需要根据文档同时更新文档的公有和私有 |
| 437 | func (this *ElasticSearchClient) SetBookPublic(bookId int, public bool) (err error) { |
| 438 | if !this.On { |
| 439 | return |
| 440 | } |
| 441 | |
| 442 | if bookId <= 0 { |
| 443 | return |
| 444 | } |
| 445 | |
| 446 | private := 1 |
| 447 | if public { |
| 448 | private = 0 |
| 449 | } |
| 450 | |
| 451 | apiDoc := this.Host + this.Index + "/" + this.Type + "/_update_by_query" |
| 452 | bodyDoc := fmt.Sprintf(`{"query":{"term":{"book_id":%v}},"script":{"inline":"ctx._source.private = %v"}}`, bookId, private) |
| 453 | |
| 454 | err = utils.HandleResponse(this.post(apiDoc).Body(bodyDoc).Response()) |
| 455 | if err != nil { |
| 456 | return |
| 457 | } |
| 458 | |
| 459 | apiBook := this.Host + this.Index + "/" + this.Type + "/book_" + strconv.Itoa(bookId) + "/_update" |
| 460 | bodyBook := fmt.Sprintf(`{"script" : "ctx._source.private=%v"}`, private) |
| 461 | err = utils.HandleResponse(this.post(apiBook).Body(bodyBook).Response()) |
| 462 | return |
| 463 | } |
| 464 | |
| 465 | //创建索引 |
| 466 | func (this *ElasticSearchClient) BuildIndex(es ElasticSearchData) (err error) { |
no test coverage detected