| 1 | package Elastic::Model::0_90::Store; | ||
| 2 | $Elastic::Model::0_90::Store::VERSION = '0.52'; | ||
| 3 | use Moose; | ||
| 4 | |||
| 5 | with 'Elastic::Model::Role::Store'; | ||
| 6 | use namespace::autoclean; | ||
| 7 | |||
| 8 | my @Top_Level = qw( | ||
| 9 | index type lenient | ||
| 10 | preference routing scroll | ||
| 11 | search_type timeout version | ||
| 12 | ); | ||
| 13 | |||
| 14 | #=================================== | ||
| 15 | sub search { | ||
| 16 | #=================================== | ||
| 17 | my $self = shift; | ||
| 18 | my $args = _tidy_search( $self, @_ ); | ||
| 19 | $self->es->search($args); | ||
| 20 | } | ||
| 21 | |||
| 22 | #=================================== | ||
| 23 | sub scrolled_search { | ||
| 24 | #=================================== | ||
| 25 | my $self = shift; | ||
| 26 | my $args = _tidy_search( $self, @_ ); | ||
| 27 | $self->es->scroll_helper($args); | ||
| 28 | } | ||
| 29 | |||
| 30 | #=================================== | ||
| 31 | sub _tidy_search { | ||
| 32 | #=================================== | ||
| 33 | my $self = shift; | ||
| 34 | my %body = ref $_[0] eq 'HASH' ? %{ shift() } : @_; | ||
| 35 | my %args; | ||
| 36 | for (@Top_Level) { | ||
| 37 | my $val = delete $body{$_}; | ||
| 38 | if ( defined $val ) { | ||
| 39 | $args{$_} = $val; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | if ( $self->es->isa('Search::Elasticsearch::Client::0_90::Direct') ) { | ||
| 43 | if ( delete $body{_source} ) { | ||
| 44 | push @{ $body{fields} }, '_source' | ||
| 45 | unless grep { $_ eq '_source' } @{ $body{fields} }; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | $args{body} = \%body; | ||
| 49 | return \%args; | ||
| 50 | } | ||
| 51 | #=================================== | ||
| 52 | sub delete_by_query { | ||
| 53 | #=================================== | ||
| 54 | my $self = shift; | ||
| 55 | my $args = _tidy_search( $self, @_ ); | ||
| 56 | $args->{body} = $args->{body}{query}; | ||
| 57 | my $result = eval { $self->es->delete_by_query($args) }; | ||
| 58 | return $result if $result; | ||
| 59 | die $@ unless $@ =~ /request does not support/; | ||
| 60 | $args->{body} = { query => $args->{body} }; | ||
| 61 | $self->es->delete_by_query($args); | ||
| 62 | } | ||
| 63 | |||
| 64 | #=================================== | ||
| 65 | sub get_doc { | ||
| 66 | #=================================== | ||
| 67 | my ( $self, $uid, %args ) = @_; | ||
| 68 | return $self->es->get( | ||
| 69 | fields => [qw(_routing _parent _source)], | ||
| 70 | %{ $uid->read_params }, | ||
| 71 | %args, | ||
| 72 | ); | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | #=================================== | ||
| 77 | sub get_mapping { | ||
| 78 | #=================================== | ||
| 79 | my $self = shift; | ||
| 80 | my %args = _cleanup(@_); | ||
| 81 | my $result = $self->es->indices->get_mapping(%args); | ||
| 82 | for ( keys %$result ) { | ||
| 83 | next unless $result->{$_}; | ||
| 84 | return $result if $result->{$_}{mappings}; | ||
| 85 | $result->{$_} = { mappings => $result->{$_} }; | ||
| 86 | } | ||
| 87 | return $result; | ||
| 88 | } | ||
| 89 | |||
| 90 | #=================================== | ||
| 91 | sub put_mapping { | ||
| 92 | #=================================== | ||
| 93 | my ( $self, %args ) = @_; | ||
| 94 | $args{body} = { $args{type} => delete $args{mapping} }; | ||
| 95 | return $self->es->indices->put_mapping(%args); | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; | ||
| 99 | |||
| 100 | =pod | ||
| 101 | |||
| 102 | =encoding UTF-8 | ||
| 103 | |||
| 104 | =head1 NAME | ||
| 105 | |||
| 106 | Elastic::Model::0_90::Store - A 0.90.x compatibility class for Elastic::Model::Store | ||
| 107 | |||
| 108 | =head1 VERSION | ||
| 109 | |||
| 110 | version 0.52 | ||
| 111 | |||
| 112 | =head1 DESCRIPTION | ||
| 113 | |||
| 114 | L<Elastic::Model::0_90::Store> handles differences between Elasticsearch 0.90.x | ||
| 115 | and 1.x, specifically to do with partial fields, get and put mapping responses, | ||
| 116 | and delete-by-query. | ||
| 117 | |||
| 118 | See L<Elastic::Manual::Delta> for more information about enabling | ||
| 119 | the 0.90.x compatibility mode. | ||
| 120 | |||
| 121 | =head1 AUTHOR | ||
| 122 | |||
| 123 | Clinton Gormley <drtech@cpan.org> | ||
| 124 | |||
| 125 | =head1 COPYRIGHT AND LICENSE | ||
| 126 | |||
| 127 | This software is copyright (c) 2015 by Clinton Gormley. | ||
| 128 | |||
| 129 | This is free software; you can redistribute it and/or modify it under | ||
| 130 | the same terms as the Perl 5 programming language system itself. | ||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | __END__ |