Browse files

update_mapping() and delete_mapping() now accept optional args, which

get passed to ElasticSearch.pm

Closes #27
  • Loading branch information...
1 parent d0db508 commit adfb41a280dc50d34cbdab1fb85ee7721c895e3a @clintongormley committed Jan 4, 2013
Showing with 21 additions and 3 deletions.
  1. +14 −3 lib/Elastic/Model/Role/Index.pm
  2. +7 −0 t/20_namespace/04_index_role.t
View
17 lib/Elastic/Model/Role/Index.pm
@@ -117,14 +117,16 @@ sub is_index {
sub update_mapping {
#===================================
my $self = shift;
+ my %args = ref $_[-1] eq 'HASH' ? %{ pop() } : ();
my $mappings = $self->mappings(@_);
my $es = $self->es;
my $name = $self->name;
for my $type ( keys %$mappings ) {
$es->put_mapping(
index => $name,
type => $type,
- mapping => $mappings->{$type}
+ mapping => $mappings->{$type},
+ %args,
);
}
return $self;
@@ -134,9 +136,10 @@ sub update_mapping {
sub delete_mapping {
#===================================
my $self = shift;
+ my %args = ref $_[-1] eq 'HASH' ? %{ pop() } : ();
my $es = $self->es;
my $name = $self->name;
- $es->delete_mapping( index => $name, type => $_ ) for @_;
+ $es->delete_mapping( index => $name, type => $_, %args ) for @_;
return $self;
}
@@ -270,6 +273,7 @@ L</namespace>.
$admin = $admin->update_mapping();
$admin = $admin->update_mapping( @type_names );
+ $admin = $admin->update_mapping( @type_names, { ignore_conflicts=> 1 } );
Type mappings B<cannot be changed> on an existing index, but they B<can be
added to>. L</update_mapping()> will generate a new type mapping from your
@@ -281,12 +285,19 @@ update all types known to the L</namespace>.
$admin->update_mapping( 'user','post');
+Any optional args passed
+as a hashref as the final parameter will be passed to
+L<ElasticSearch/put_mapping()>
+
=head2 delete_mapping();
$admin = $admin->delete_mapping( @types );
+ $admin = $admin->delete_mapping( @types, { ignore_missing => 1 });
Deletes the type mapping B<AND THE DOCUMENTS> for the listed types in the index
-(or the indices pointed to by alias) L</name>.
+(or the indices pointed to by alias) L</name>. Any optional args passed
+as a hashref as the final parameter will be passed to
+L<ElasticSearch/delete_mapping()>.
=head2 exists()
View
7 t/20_namespace/04_index_role.t
@@ -5,6 +5,7 @@ use warnings;
use Test::More 0.96;
use Test::Moose;
use Test::Deep;
+use Test::Exception;
use lib 't/lib';
@@ -80,6 +81,12 @@ sub test_domain {
ok $es->mapping( index => $name, type => "post" )->{post},
"Mapping $desc recreated";
+ throws_ok sub { $index->delete_mapping("foo") }, qr/Missing/,
+ "Non-existent mapping throws error";
+
+ ok $index->delete_mapping( "foo", { ignore_missing => 1 } ),
+ "Ignore missing mapping";
+
## Refresh ##
ok $index->refresh, "$desc refreshed";

0 comments on commit adfb41a

Please sign in to comment.