-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreindex.go
48 lines (44 loc) · 831 Bytes
/
reindex.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
package eskeeper
import (
"context"
"fmt"
"io/ioutil"
"strings"
)
func (c *esclient) reindex(ctx context.Context, dest string, reindex reindex) error {
ri := c.client.Reindex
body := strings.NewReader(
fmt.Sprintf(`
{
"source": {
"index": "%s"
},
"dest": {
"index": "%s"
}
}`,
reindex.Source, dest,
),
)
slices := reindex.Slices
if slices == 0 {
slices = 1
}
res, err := ri(
body,
ri.WithContext(ctx),
ri.WithSlices(slices),
ri.WithWaitForCompletion(reindex.WaitForCompletion),
)
if err != nil {
return fmt.Errorf("reindex: %w", err)
}
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
return fmt.Errorf("failed to reindex [index=%v, statusCode=%v, res=%v]", reindex.Source, res.StatusCode, string(body))
}
return nil
}