-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Reindexer
Reindexing is e.g. necessary when you want to apply changes to your mapping in existing data. However, reindexing is currently a client-side operation. To make things easier for application programmers, Elastic contains a helper to reindex indices, even between clusters.
The Elasticsearch documentation has a section about reindexing if you want more information.
Here's an example of the Reindexer with various options:
client, err := elastic.NewClient()
if err != nil { ... }
ix := client.Reindex("source", "target")
ix = ix.Progress(func(current, total int64) {
fmt.Printf("%d of %d\r", current, total)
})
result, err := ix.Do()
if err != nil { ... }
fmt.Printf("%d operations succeeded, %d failed", result.Success, result.Failed)As you see in the example above, you can provide a progress callback function with Progress(func(int64,int64)).
If you need more information about which bulk item requests exactly failed, use StatsOnly(false). The result will then contain all failed items in result.Errors ([]*elastic.BulkResponseItem).
If you need to copy data from one cluster to another, create a second client for the new cluster and set it with TargetClient(*elastic.Client).
You can also specify the chunk size of bulk items sent to Elasticsearch with BulkSize(int). The default is 500.
Also, a scroll timeout can be specified with Scroll(string), e.g. Scroll("15m"). The default is 5 minutes (5m).