Skip to content

Commit

Permalink
Add support for automatic slicing in Reindex API
Browse files Browse the repository at this point in the history
As of Elasticsearch 5.1, there is a support for automatically slicing
the reindexing task. See
https://www.elastic.co/guide/en/elasticsearch/reference/5.1/docs-reindex.html#docs-reindex-automatic-slice
for details.

This commit supports the setting for the v5 branch.

See #706
  • Loading branch information
olivere committed Feb 14, 2018
1 parent 3d6edfd commit ad28867
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -68,6 +68,7 @@ Joe Buck [@four2five](https://github.com/four2five)
John Barker [@j16r](https://github.com/j16r)
John Goodall [@jgoodall](https://github.com/jgoodall)
John Stanford [@jxstanford](https://github.com/jxstanford)
Jonas Groenaas Drange [@semafor](https://github.com/semafor)
Josh Chorlton [@jchorl](https://github.com/jchorl)
jun [@coseyo](https://github.com/coseyo)
Junpei Tsuji [@jun06t](https://github.com/jun06t)
Expand Down
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -26,7 +26,7 @@ import (

const (
// Version is the current version of Elastic.
Version = "5.0.63"
Version = "5.0.64"

// DefaultURL is the default endpoint of Elasticsearch on the local machine.
// It is used e.g. when initializing a new Client without a specific URL.
Expand Down
10 changes: 10 additions & 0 deletions reindex.go
Expand Up @@ -20,6 +20,7 @@ type ReindexService struct {
waitForActiveShards string
waitForCompletion *bool
requestsPerSecond *int
slices *int
body interface{}
source *ReindexSource
destination *ReindexDestination
Expand Down Expand Up @@ -51,6 +52,12 @@ func (s *ReindexService) RequestsPerSecond(requestsPerSecond int) *ReindexServic
return s
}

// Slices specifies the number of slices this task should be divided into. Defaults to 1.
func (s *ReindexService) Slices(slices int) *ReindexService {
s.slices = &slices
return s
}

// Refresh indicates whether Elasticsearch should refresh the effected indexes
// immediately.
func (s *ReindexService) Refresh(refresh string) *ReindexService {
Expand Down Expand Up @@ -179,6 +186,9 @@ func (s *ReindexService) buildURL() (string, url.Values, error) {
if s.requestsPerSecond != nil {
params.Set("requests_per_second", fmt.Sprintf("%v", *s.requestsPerSecond))
}
if s.slices != nil {
params.Set("slices", fmt.Sprintf("%v", *s.slices))
}
if s.waitForActiveShards != "" {
params.Set("wait_for_active_shards", s.waitForActiveShards)
}
Expand Down

0 comments on commit ad28867

Please sign in to comment.