Skip to content

Commit

Permalink
Merge pull request #481 from CPAN-API/mickey/fix_backup
Browse files Browse the repository at this point in the history
fix backup script (use update when id exists)
  • Loading branch information
oalders committed May 17, 2016
2 parents c0f7664 + 432e730 commit c022205
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/MetaCPAN/Script/Backup.pm
Expand Up @@ -152,14 +152,31 @@ sub run_restore {
}
}

$bulk->create(
{
id => $raw->{_id},
$parent ? ( parent => $parent ) : (),
source => $raw->{_source},
}
my $exists = $es->exists(
index => $raw->{_index},
type => $raw->{_type},
id => $raw->{_id},
);

if ($exists) {
$bulk->update(
{
id => $raw->{_id},
doc => $raw->{_source},
doc_as_upsert => 1,
}
);

}
else {
$bulk->create(
{
id => $raw->{_id},
$parent ? ( parent => $parent ) : (),
source => $raw->{_source},
}
);
}
}

# Flush anything left over just incase
Expand Down

0 comments on commit c022205

Please sign in to comment.