diff --git a/lib/Elastic/Model/Result.pm b/lib/Elastic/Model/Result.pm index 51ccb23..ff3f39c 100644 --- a/lib/Elastic/Model/Result.pm +++ b/lib/Elastic/Model/Result.pm @@ -13,10 +13,6 @@ around BUILDARGS => sub { my $class = shift; my $params = ref $_[0] eq 'HASH' ? shift : {@_}; my $fields = $params->{result}{fields}; - if ( my $partial = delete $fields->{_partial_doc} ) { - $params->{result}{_source} - = ref $partial eq 'ARRAY' ? $partial->[0] : $partial; - } for ( keys %$fields ) { next if substr( $_, 0, 1 ) eq '_'; $fields->{$_} = [ $fields->{$_} ] diff --git a/lib/Elastic/Model/Role/Store.pm b/lib/Elastic/Model/Role/Store.pm index bd21f52..0aa241c 100644 --- a/lib/Elastic/Model/Role/Store.pm +++ b/lib/Elastic/Model/Role/Store.pm @@ -23,7 +23,7 @@ my @Top_Level = qw( sub search { #=================================== my $self = shift; - my $args = _tidy_search(@_); + my $args = _tidy_search( $self, @_ ); $self->es->search($args); } @@ -31,13 +31,14 @@ sub search { sub scrolled_search { #=================================== my $self = shift; - my $args = _tidy_search(@_); + my $args = _tidy_search( $self, @_ ); $self->es->scroll_helper($args); } #=================================== sub _tidy_search { #=================================== + my $self = shift; my %body = ref $_[0] eq 'HASH' ? %{ shift() } : @_; my %args; for (@Top_Level) { @@ -46,9 +47,11 @@ sub _tidy_search { $args{$_} = $val; } } - my $source; - if ( $source = delete $body{_source} ) { - $body{partial_fields}{_partial_doc} = $source; + if ( $self->es->isa('Search::Elasticsearch::Client::0_90::Direct') ) { + if ( delete $body{_source} ) { + push @{ $body{fields} }, '_source' + unless grep { $_ eq '_source' } @{ $body{fields} }; + } } $args{body} = \%body; return \%args; @@ -57,7 +60,7 @@ sub _tidy_search { sub delete_by_query { #=================================== my $self = shift; - my $args = _tidy_search(@_); + my $args = _tidy_search( $self, @_ ); $args->{body} = $args->{body}{query}; my $result = eval { $self->es->delete_by_query($args) }; return $result if $result; diff --git a/t/20_namespace/04_index_role.t b/t/20_namespace/04_index_role.t index fd8a784..1e672e9 100644 --- a/t/20_namespace/04_index_role.t +++ b/t/20_namespace/04_index_role.t @@ -95,8 +95,7 @@ sub test_domain { sub get_interval { my $name = shift; my $settings - = $es->indices->get_settings( index => $name ) - ->{myapp3}{settings}; + = $es->indices->get_settings( index => $name )->{myapp3}{settings}; return $settings->{"index.refresh_interval"} || $settings->{index}{refresh_interval}; } @@ -135,8 +134,7 @@ SKIP: { my $name = shift; my $settings = $es->indices->get_settings( index => $name ) ->{myapp3}{settings}; - return $settings->{ - "index.analysis.analyzer.edge_ngrams.tokenizer"} + return $settings->{"index.analysis.analyzer.edge_ngrams.tokenizer"} || $settings->{index}{analysis}{analyzer}{edge_ngrams} {tokenizer}; } diff --git a/t/40_view/03_results.t b/t/40_view/03_results.t index 62f8180..c39391e 100644 --- a/t/40_view/03_results.t +++ b/t/40_view/03_results.t @@ -11,6 +11,8 @@ use lib 't/lib'; our ( $es, $store ); do 'es.pl'; +our $is_090 = $es->isa('Search::Elasticsearch::Client::0_90::Direct'); + use_ok 'MyApp' || print 'Bail out'; my $model = new_ok( 'MyApp', [ es => $es ], 'Model' ); @@ -130,8 +132,7 @@ throws_ok sub { $it->index(-1000) }, qr/out of bounds/, 'Index out of bounds'; $it->reset; is $it->_i, -1, 'Reset'; -throws_ok sub { $it->index(20) }, qr/Values can be 0..9/, - 'Index out of bounds'; +throws_ok sub { $it->index(20) }, qr/Values can be 0..9/, 'Index out of bounds'; $it->shift for 1 .. 10; throws_ok sub { $it->index(0) }, qr/ No values/, 'Empty index out of bounds'; @@ -249,8 +250,11 @@ sub test_single { "$desc $name as partials - $id"; is $r->uid->is_partial, 1, "$desc $name as partials is partial"; ok $r->name, "$desc $name as partials has name"; - ok !$r->{timestamp}, "$desc $name as partials has no timestamp"; + SKIP: { + skip "Partials not supported in 0.90", 1 if $is_090; + ok !$r->{timestamp}, "$desc $name as partials has no timestamp"; + } } else { is my $r = $it->$el_method, undef, "$desc $el_method - undef"; diff --git a/t/40_view/06_result.t b/t/40_view/06_result.t index 97d31d7..270ddd8 100644 --- a/t/40_view/06_result.t +++ b/t/40_view/06_result.t @@ -125,7 +125,12 @@ isa_ok $result = $view->queryb( { name => 'Aardwolf' } ) # isa_ok my $doc = $result->partial, 'MyApp::User', 'Partial->partial'; ok $doc->{name}, 'Partial has name'; -ok !$doc->{timestamp}, 'Partial has no timestamp'; +SKIP: { + skip "Partials not supported in 0.90", 1 + if $es->isa('Search::Elasticsearch::Client::0_90::Direct'); + ok !$doc->{timestamp}, 'Partial has no timestamp'; +} + ok $doc->uid->is_partial, 'Partial UID is partial'; isa_ok $doc = $result->object, 'MyApp::User', 'Partial->object';