Yervand Aghababyan
Yervand Aghababyan

Reputation: 1140

Re-indexing an index in ElasticSearch to change the number of shards

I need to change the number of shards in my index. The index is quite big and i may have to change the configuration 10-15 times for testing purposes before i'm satisfied with the result. is there a tool offering out of the box this kind of functionality? or what's the easiest way of accomplishing this?

Upvotes: 4

Views: 4478

Answers (1)

karmi
karmi

Reputation: 14429

Both the Perl and Ruby clients directly support reindexing.

In Perl, you'd do:

my $source = $es->scrolled_search(
    index       => 'old_index',
    search_type => 'scan',
    scroll      => '5m',
    version     => 1
);

$es->reindex(
    source      => $source,
    dest_index  => 'new_index'
);

Find more information in the post by Clinton Gormley.

In Ruby, you'd do:

Tire.index('old').reindex 'new', settings: { number_of_shards: 3 }

Find more information in the relevant Tire commit.

Upvotes: 7

Related Questions