From ad2886760fe843ee9e396ac2e2bf2ff95ee7bc5d Mon Sep 17 00:00:00 2001 From: Oliver Eilhard Date: Wed, 14 Feb 2018 11:16:41 +0100 Subject: [PATCH] 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/5.1/docs-reindex.html#docs-reindex-automatic-slice for details. This commit supports the setting for the v5 branch. See #706 --- CONTRIBUTORS | 1 + client.go | 2 +- reindex.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e75263a62..ba06dac29 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -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) diff --git a/client.go b/client.go index 8a268fe85..30fb8ff90 100644 --- a/client.go +++ b/client.go @@ -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. diff --git a/reindex.go b/reindex.go index 4650fb18b..60f6f8cee 100644 --- a/reindex.go +++ b/reindex.go @@ -20,6 +20,7 @@ type ReindexService struct { waitForActiveShards string waitForCompletion *bool requestsPerSecond *int + slices *int body interface{} source *ReindexSource destination *ReindexDestination @@ -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 { @@ -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) }