Skip to content

Commit

Permalink
script/mapping: improved index cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Dec 8, 2016
1 parent 01f3aeb commit 6b06a90
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions lib/MetaCPAN/Script/Mapping.pm
Expand Up @@ -106,7 +106,7 @@ sub run {
$self->index_create if $self->create_index;
$self->index_delete if $self->delete_index;
$self->index_update if $self->update_index;
$self->copy_index if $self->copy_to_index;
$self->type_copy if $self->copy_to_index;
$self->type_empty if $self->delete_from_type;
$self->types_list if $self->list_types;
$self->delete_mapping if $self->delete;
Expand Down Expand Up @@ -210,12 +210,7 @@ sub index_create {
)
{
log_info {"Re-indexing data to index $dst_idx from type: $type"};
my $bulk = $self->es->bulk_helper(
index => $dst_idx,
type => $type,
);
$bulk->reindex( source => { index => $self->index->name }, );
$bulk->flush;
$self->type_copy( $dst_idx, $type );
}
}

Expand All @@ -226,11 +221,13 @@ sub index_create {
if @patch_types;
}

sub copy_index {
my $self = shift;
sub type_copy {
my ( $self, $index, $type ) = @_;
$index //= $self->copy_to_index;

$self->_check_index_exists( $self->copy_to_index, EXPECTED );
$self->copy_type or die "can't copy without a type\n";
$self->_check_index_exists( $index, EXPECTED );
$type //= $self->copy_type;
$type or die "can't copy without a type\n";

my $arg_query = $self->copy_query;
my $query
Expand All @@ -248,7 +245,7 @@ sub copy_index {
};
}

return $self->_copy_slice($query) if $query;
return $self->_copy_slice($query, $index, $type) if $query;

# else ... do copy by monthly slices

Expand All @@ -264,7 +261,7 @@ sub copy_index {

log_info {"copying data for month: $gte"};
eval {
$self->_copy_slice($q);
$self->_copy_slice($q, $index, $type);
1;
} or do {
my $err = $@ || 'zombie error';
Expand All @@ -274,14 +271,14 @@ sub copy_index {
}

sub _copy_slice {
my ( $self, $query ) = @_;
my ( $self, $query, $index, $type ) = @_;

my $scroll = $self->es()->scroll_helper(
search_type => 'scan',
size => 250,
scroll => '10m',
index => $self->index->name,
type => $self->copy_type,
type => $type,
body => {
query => {
filtered => {
Expand All @@ -292,8 +289,8 @@ sub _copy_slice {
);

my $bulk = $self->es->bulk_helper(
index => $self->copy_to_index,
type => $self->copy_type,
index => $index,
type => $type,
max_count => 500,
);

Expand Down

0 comments on commit 6b06a90

Please sign in to comment.