Skip to content

Commit

Permalink
Add size parameter to reindexer
Browse files Browse the repository at this point in the history
Watch out: Size is the number of documents to return *per shard*, not
per request!

Thanks @guilherme-santos. Closes olivere#132.
  • Loading branch information
olivere committed Sep 22, 2015
1 parent 855cc76 commit 186e001
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions reindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Reindexer struct {
query Query
scanFields []string
bulkSize int
size int
scroll string
reindexerFunc ReindexerFunc
progress ReindexerProgressFunc
Expand Down Expand Up @@ -116,8 +117,16 @@ func (ix *Reindexer) ScanFields(scanFields ...string) *Reindexer {

// BulkSize returns the number of documents to send to Elasticsearch per chunk.
// The default is 500.
func (ix *Reindexer) BulkSize(size int) *Reindexer {
ix.bulkSize = size
func (ix *Reindexer) BulkSize(bulkSize int) *Reindexer {
ix.bulkSize = bulkSize
return ix
}

// Size is the number of results to return per shard, not per request.
// So a size of 10 which hits 5 shards will return a maximum of 50 results
// per scan request.
func (ix *Reindexer) Size(size int) *Reindexer {
ix.size = size
return ix
}

Expand Down Expand Up @@ -179,6 +188,9 @@ func (ix *Reindexer) Do() (*ReindexerResponse, error) {
if ix.query != nil {
scanner = scanner.Query(ix.query)
}
if ix.size > 0 {
scanner = scanner.Size(ix.size)
}
cursor, err := scanner.Do()

bulk := ix.targetClient.Bulk()
Expand Down
3 changes: 3 additions & 0 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func (s *ScanService) Pretty(pretty bool) *ScanService {
return s
}

// Size is the number of results to return per shard, not per request.
// So a size of 10 which hits 5 shards will return a maximum of 50 results
// per scan request.
func (s *ScanService) Size(size int) *ScanService {
s.size = &size
return s
Expand Down

0 comments on commit 186e001

Please sign in to comment.