Skip to content

Commit 9f4560b

Browse files
committed
Add support for automatic slicing in Reindex API
As of Elasticsearch 5.1, there is a support for automatically slicing the reindexing task. See https://www.elastic.co/guide/en/elasticsearch/reference/6.1/docs-reindex.html#docs-reindex-automatic-slice for details. This commit supports the setting for the v6 branch. See #706
1 parent c26049b commit 9f4560b

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Joe Buck [@four2five](https://github.com/four2five)
6868
John Barker [@j16r](https://github.com/j16r)
6969
John Goodall [@jgoodall](https://github.com/jgoodall)
7070
John Stanford [@jxstanford](https://github.com/jxstanford)
71+
Jonas Groenaas Drange [@semafor](https://github.com/semafor)
7172
Josh Chorlton [@jchorl](https://github.com/jchorl)
7273
jun [@coseyo](https://github.com/coseyo)
7374
Junpei Tsuji [@jun06t](https://github.com/jun06t)

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
const (
2828
// Version is the current version of Elastic.
29-
Version = "6.1.6"
29+
Version = "6.1.7"
3030

3131
// DefaultURL is the default endpoint of Elasticsearch on the local machine.
3232
// It is used e.g. when initializing a new Client without a specific URL.

errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (e *Error) Error() string {
9494
// IsConnErr returns true if the error indicates that Elastic could not
9595
// find an Elasticsearch host to connect to.
9696
func IsConnErr(err error) bool {
97-
return errors.Cause(err) == ErrNoClient
97+
return err == ErrNoClient || errors.Cause(err) == ErrNoClient
9898
}
9999

100100
// IsNotFound returns true if the given error indicates that Elasticsearch

reindex.go

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ReindexService struct {
2020
waitForActiveShards string
2121
waitForCompletion *bool
2222
requestsPerSecond *int
23+
slices *int
2324
body interface{}
2425
source *ReindexSource
2526
destination *ReindexDestination
@@ -51,6 +52,12 @@ func (s *ReindexService) RequestsPerSecond(requestsPerSecond int) *ReindexServic
5152
return s
5253
}
5354

55+
// Slices specifies the number of slices this task should be divided into. Defaults to 1.
56+
func (s *ReindexService) Slices(slices int) *ReindexService {
57+
s.slices = &slices
58+
return s
59+
}
60+
5461
// Refresh indicates whether Elasticsearch should refresh the effected indexes
5562
// immediately.
5663
func (s *ReindexService) Refresh(refresh string) *ReindexService {
@@ -179,6 +186,9 @@ func (s *ReindexService) buildURL() (string, url.Values, error) {
179186
if s.requestsPerSecond != nil {
180187
params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond))
181188
}
189+
if s.slices != nil {
190+
params.Set("slices", fmt.Sprintf("%v", *s.slices))
191+
}
182192
if s.waitForActiveShards != "" {
183193
params.Set("wait_for_active_shards", s.waitForActiveShards)
184194
}

0 commit comments

Comments
 (0)