diff --git a/lib/MetaCPAN/Script/Author.pm b/lib/MetaCPAN/Script/Author.pm index 8d08009bb..d306983c8 100644 --- a/lib/MetaCPAN/Script/Author.pm +++ b/lib/MetaCPAN/Script/Author.pm @@ -135,11 +135,10 @@ sub index_authors { ); my $scroll = $self->es->scroll_helper( - index => $self->index->name, - type => 'author', - search_type => 'scan', - size => 500, - body => { + index => $self->index->name, + type => 'author', + size => 500, + body => { query => { $self->pauseid ? ( @@ -150,6 +149,7 @@ sub index_authors { : ( match_all => {} ), }, _source => [@compare_fields], + sort => '_doc', }, ); diff --git a/lib/MetaCPAN/Script/Backup.pm b/lib/MetaCPAN/Script/Backup.pm index ab3ddd159..9f0c7c3ca 100644 --- a/lib/MetaCPAN/Script/Backup.pm +++ b/lib/MetaCPAN/Script/Backup.pm @@ -75,10 +75,12 @@ sub run { my $scroll = $es->scroll_helper( index => $self->index->name, $self->type ? ( type => $self->type ) : (), - size => $self->size, - search_type => 'scan', - fields => [qw(_parent _source)], - scroll => '1m', + size => $self->size, + fields => [qw(_parent _source)], + scroll => '1m', + body => { + sort => '_doc', + }, ); log_info { 'Backing up ', $scroll->total, ' documents' }; diff --git a/lib/MetaCPAN/Script/CPANTesters.pm b/lib/MetaCPAN/Script/CPANTesters.pm index bdc126616..bf2fa3ad4 100644 --- a/lib/MetaCPAN/Script/CPANTesters.pm +++ b/lib/MetaCPAN/Script/CPANTesters.pm @@ -85,10 +85,12 @@ sub index_reports { bunzip2 "$db.bz2" => "$db", AutoClose => 1 if -e "$db.bz2"; my $scroll = $es->scroll_helper( - index => $self->index->name, - search_type => 'scan', - size => '500', - type => 'release', + index => $self->index->name, + size => '500', + type => 'release', + body => { + sort => '_doc', + }, ); my %releases; diff --git a/lib/MetaCPAN/Script/CPANTestersAPI.pm b/lib/MetaCPAN/Script/CPANTestersAPI.pm index c5465d1e2..b690c621a 100644 --- a/lib/MetaCPAN/Script/CPANTestersAPI.pm +++ b/lib/MetaCPAN/Script/CPANTestersAPI.pm @@ -62,10 +62,12 @@ sub index_reports { my $data = decode_json $json; my $scroll = $es->scroll_helper( - index => $self->index->name, - search_type => 'scan', - size => '500', - type => 'release', + index => $self->index->name, + size => '500', + type => 'release', + body => { + sort => '_doc', + }, ); # Create a cache of all releases (dist + version combos) diff --git a/lib/MetaCPAN/Script/Favorite.pm b/lib/MetaCPAN/Script/Favorite.pm index afc7a55e4..13457a6a7 100644 --- a/lib/MetaCPAN/Script/Favorite.pm +++ b/lib/MetaCPAN/Script/Favorite.pm @@ -75,7 +75,7 @@ sub run { sub index_favorites { my $self = shift; - my $body; + my $query = { match_all => {} }; my $age_filter; if ( $self->age ) { $age_filter = { @@ -86,24 +86,20 @@ sub index_favorites { } if ( $self->distribution ) { - $body = { - query => { - term => { distribution => $self->distribution } - } - }; + $query = { term => { distribution => $self->distribution } }; } elsif ( $self->age ) { my $favs = $self->es->scroll_helper( - index => $self->index->name, - type => 'favorite', - search_type => 'scan', - scroll => '5m', - fields => [qw< distribution >], - size => 500, - body => { + index => $self->index->name, + type => 'favorite', + scroll => '5m', + fields => [qw< distribution >], + size => 500, + body => { query => $age_filter, - ( $self->limit ? ( size => $self->limit ) : () ) + ( $self->limit ? ( size => $self->limit ) : () ), + sort => '_doc', } ); @@ -116,11 +112,7 @@ sub index_favorites { my @keys = keys %recent_dists; if (@keys) { - $body = { - query => { - terms => { distribution => \@keys } - } - }; + $query = { terms => { distribution => \@keys } }; } } @@ -133,13 +125,15 @@ sub index_favorites { } else { my $favs = $self->es->scroll_helper( - index => $self->index->name, - type => 'favorite', - search_type => 'scan', - scroll => '30s', - fields => [qw< distribution >], - size => 500, - ( $body ? ( body => $body ) : () ), + index => $self->index->name, + type => 'favorite', + scroll => '30s', + fields => [qw< distribution >], + size => 500, + body => { + query => $query, + sort => '_doc', + }, ); while ( my $fav = $favs->next ) { @@ -160,13 +154,12 @@ sub index_favorites { } my $files = $self->es->scroll_helper( - index => $self->index->name, - type => 'file', - search_type => 'scan', - scroll => '15m', - fields => [qw< id distribution >], - size => 500, - body => { + index => $self->index->name, + type => 'file', + scroll => '15m', + fields => [qw< id distribution >], + size => 500, + body => { query => { bool => { must_not => [ @@ -174,7 +167,8 @@ sub index_favorites { ], @age_filter, } - } + }, + sort => '_doc', }, ); @@ -236,14 +230,14 @@ sub index_favorites { ); my $files = $self->es->scroll_helper( - index => $self->index->name, - type => 'file', - search_type => 'scan', - scroll => '15s', - fields => [qw< id >], - size => 500, - body => { - query => { term => { distribution => $dist } } + index => $self->index->name, + type => 'file', + scroll => '15s', + fields => [qw< id >], + size => 500, + body => { + query => { term => { distribution => $dist } }, + sort => '_doc', }, ); diff --git a/lib/MetaCPAN/Script/Latest.pm b/lib/MetaCPAN/Script/Latest.pm index 8c9b34c28..c2f0fa8cf 100644 --- a/lib/MetaCPAN/Script/Latest.pm +++ b/lib/MetaCPAN/Script/Latest.pm @@ -265,14 +265,23 @@ sub reindex { $release->put unless ( $self->dry_run ); # Get all the files for the release. - my $scroll = $self->index->type("file")->search_type('scan')->filter( { - bool => { - must => [ - { term => { 'release' => $source->{release} } }, - { term => { 'author' => $source->{author} } } - ] - } - } )->size(100)->source( [ 'status', 'file' ] )->raw->scroll; + my $scroll = $self->es->scroll_helper( + index => $self->index->name, + type => 'file', + size => 100, + body => { + query => { + bool => { + must => [ + { term => { 'release' => $source->{release} } }, + { term => { 'author' => $source->{author} } }, + ], + }, + }, + _source => [ 'status', 'file' ], + sort => '_doc', + }, + ); while ( my $row = $scroll->next ) { my $source = $row->{_source}; diff --git a/lib/MetaCPAN/Script/Mapping.pm b/lib/MetaCPAN/Script/Mapping.pm index a8434702a..c3e3a2af5 100644 --- a/lib/MetaCPAN/Script/Mapping.pm +++ b/lib/MetaCPAN/Script/Mapping.pm @@ -411,17 +411,17 @@ sub _copy_slice { my ( $self, $query, $index, $type ) = @_; my $scroll = $self->es->scroll_helper( - search_type => 'scan', - size => 250, - scroll => '10m', - index => $self->index->name, - type => $type, - body => { + size => 250, + scroll => '10m', + index => $self->index->name, + type => $type, + body => { query => { filtered => { query => $query } - } + }, + sort => '_doc', }, ); @@ -453,12 +453,14 @@ sub empty_type { ); my $scroll = $self->es->scroll_helper( - search_type => 'scan', - size => 250, - scroll => '10m', - index => $self->index->name, - type => $type, - body => { query => { match_all => {} } }, + size => 250, + scroll => '10m', + index => $self->index->name, + type => $type, + body => { + query => { match_all => {} }, + sort => '_doc', + }, ); my @ids; diff --git a/lib/MetaCPAN/Script/Suggest.pm b/lib/MetaCPAN/Script/Suggest.pm index ebd47c75b..8a80ffb3b 100644 --- a/lib/MetaCPAN/Script/Suggest.pm +++ b/lib/MetaCPAN/Script/Suggest.pm @@ -63,20 +63,20 @@ sub _update_slice { my ( $self, $range ) = @_; my $files = $self->es->scroll_helper( - index => $self->index->name, - type => 'file', - search_type => 'scan', - scroll => '5m', - fields => [qw< id documentation >], - size => 500, - body => { + index => $self->index->name, + type => 'file', + scroll => '5m', + fields => [qw< id documentation >], + size => 500, + body => { query => { bool => { must => [ { exists => { field => "documentation" } }, $range ], - } - } + }, + }, + sort => '_doc', }, ); diff --git a/lib/MetaCPAN/Script/Watcher.pm b/lib/MetaCPAN/Script/Watcher.pm index 62fbba9e7..1cad62d23 100644 --- a/lib/MetaCPAN/Script/Watcher.pm +++ b/lib/MetaCPAN/Script/Watcher.pm @@ -109,8 +109,9 @@ sub backpan_changes { filter => { term => { status => 'backpan' } } } }, - } - } + }, + }, + sort => '_doc', } } ); my @changes; @@ -183,13 +184,12 @@ sub reindex_release { my $es = $self->es; my $scroll = $es->scroll_helper( { - index => $self->index->name, - type => 'file', - scroll => '1m', - size => 1000, - search_type => 'scan', - fields => [ '_parent', '_source' ], - body => { + index => $self->index->name, + type => 'file', + scroll => '1m', + size => 1000, + fields => [ '_parent', '_source' ], + body => { query => { filtered => { query => { match_all => {} }, @@ -208,8 +208,9 @@ sub reindex_release { ] } } - } - } + }, + sort => '_doc', + }, } ); return if ( $self->dry_run );