/
indices_flush.go
61 lines (50 loc) · 1023 Bytes
/
indices_flush.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package esx
import (
"encoding/json"
"fmt"
)
// {
// "_shards" : {
// "total" : 2,
// "successful" : 2,
// "failed" : 0
// }
// }
type flushRespTemp struct {
Shards struct {
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
} `json:"_shards"`
Status int `json:"status"`
}
// Flush 刷新index
// true => 成功, false => 失败
func Flush(client *Client, indexname string) bool {
uri := fmt.Sprintf("%s/_flush", indexname)
code, rdata := client.GetResponse("POST", uri, "", map[string]string{})
if code >= 400 {
return false
}
var resp flushRespTemp
err := json.Unmarshal(rdata, &resp)
if err != nil {
return false
}
if resp.Status >= 400 {
return false
}
if resp.Shards.Failed > 0 {
return false
}
return true
}
// FlushWithPool 刷新index
// true => 成功, false => 失败
func FlushWithPool(indexname string) bool {
client := Pool.Get()
if client != nil {
defer Pool.Put(client)
}
return Flush(client, indexname)
}