Skip to content

Commit 179eb32

Browse files
authored
Merge pull request #1261 from metacpan/haarg/remove-search_type-scan
remove use of search_type scan
2 parents 23af37b + 41d4fa9 commit 179eb32

File tree

9 files changed

+112
-100
lines changed

9 files changed

+112
-100
lines changed

lib/MetaCPAN/Script/Author.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ sub index_authors {
135135
);
136136

137137
my $scroll = $self->es->scroll_helper(
138-
index => $self->index->name,
139-
type => 'author',
140-
search_type => 'scan',
141-
size => 500,
142-
body => {
138+
index => $self->index->name,
139+
type => 'author',
140+
size => 500,
141+
body => {
143142
query => {
144143
$self->pauseid
145144
? (
@@ -150,6 +149,7 @@ sub index_authors {
150149
: ( match_all => {} ),
151150
},
152151
_source => [@compare_fields],
152+
sort => '_doc',
153153
},
154154
);
155155

lib/MetaCPAN/Script/Backup.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ sub run {
7575
my $scroll = $es->scroll_helper(
7676
index => $self->index->name,
7777
$self->type ? ( type => $self->type ) : (),
78-
size => $self->size,
79-
search_type => 'scan',
80-
fields => [qw(_parent _source)],
81-
scroll => '1m',
78+
size => $self->size,
79+
fields => [qw(_parent _source)],
80+
scroll => '1m',
81+
body => {
82+
sort => '_doc',
83+
},
8284
);
8385

8486
log_info { 'Backing up ', $scroll->total, ' documents' };

lib/MetaCPAN/Script/CPANTesters.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ sub index_reports {
8585
bunzip2 "$db.bz2" => "$db", AutoClose => 1 if -e "$db.bz2";
8686

8787
my $scroll = $es->scroll_helper(
88-
index => $self->index->name,
89-
search_type => 'scan',
90-
size => '500',
91-
type => 'release',
88+
index => $self->index->name,
89+
size => '500',
90+
type => 'release',
91+
body => {
92+
sort => '_doc',
93+
},
9294
);
9395

9496
my %releases;

lib/MetaCPAN/Script/CPANTestersAPI.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ sub index_reports {
6262
my $data = decode_json $json;
6363

6464
my $scroll = $es->scroll_helper(
65-
index => $self->index->name,
66-
search_type => 'scan',
67-
size => '500',
68-
type => 'release',
65+
index => $self->index->name,
66+
size => '500',
67+
type => 'release',
68+
body => {
69+
sort => '_doc',
70+
},
6971
);
7072

7173
# Create a cache of all releases (dist + version combos)

lib/MetaCPAN/Script/Favorite.pm

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ sub run {
7575
sub index_favorites {
7676
my $self = shift;
7777

78-
my $body;
78+
my $query = { match_all => {} };
7979
my $age_filter;
8080
if ( $self->age ) {
8181
$age_filter = {
@@ -86,24 +86,20 @@ sub index_favorites {
8686
}
8787

8888
if ( $self->distribution ) {
89-
$body = {
90-
query => {
91-
term => { distribution => $self->distribution }
92-
}
93-
};
89+
$query = { term => { distribution => $self->distribution } };
9490

9591
}
9692
elsif ( $self->age ) {
9793
my $favs = $self->es->scroll_helper(
98-
index => $self->index->name,
99-
type => 'favorite',
100-
search_type => 'scan',
101-
scroll => '5m',
102-
fields => [qw< distribution >],
103-
size => 500,
104-
body => {
94+
index => $self->index->name,
95+
type => 'favorite',
96+
scroll => '5m',
97+
fields => [qw< distribution >],
98+
size => 500,
99+
body => {
105100
query => $age_filter,
106-
( $self->limit ? ( size => $self->limit ) : () )
101+
( $self->limit ? ( size => $self->limit ) : () ),
102+
sort => '_doc',
107103
}
108104
);
109105

@@ -116,11 +112,7 @@ sub index_favorites {
116112

117113
my @keys = keys %recent_dists;
118114
if (@keys) {
119-
$body = {
120-
query => {
121-
terms => { distribution => \@keys }
122-
}
123-
};
115+
$query = { terms => { distribution => \@keys } };
124116
}
125117
}
126118

@@ -133,13 +125,15 @@ sub index_favorites {
133125
}
134126
else {
135127
my $favs = $self->es->scroll_helper(
136-
index => $self->index->name,
137-
type => 'favorite',
138-
search_type => 'scan',
139-
scroll => '30s',
140-
fields => [qw< distribution >],
141-
size => 500,
142-
( $body ? ( body => $body ) : () ),
128+
index => $self->index->name,
129+
type => 'favorite',
130+
scroll => '30s',
131+
fields => [qw< distribution >],
132+
size => 500,
133+
body => {
134+
query => $query,
135+
sort => '_doc',
136+
},
143137
);
144138

145139
while ( my $fav = $favs->next ) {
@@ -160,21 +154,21 @@ sub index_favorites {
160154
}
161155

162156
my $files = $self->es->scroll_helper(
163-
index => $self->index->name,
164-
type => 'file',
165-
search_type => 'scan',
166-
scroll => '15m',
167-
fields => [qw< id distribution >],
168-
size => 500,
169-
body => {
157+
index => $self->index->name,
158+
type => 'file',
159+
scroll => '15m',
160+
fields => [qw< id distribution >],
161+
size => 500,
162+
body => {
170163
query => {
171164
bool => {
172165
must_not => [
173166
{ range => { dist_fav_count => { gte => 1 } } }
174167
],
175168
@age_filter,
176169
}
177-
}
170+
},
171+
sort => '_doc',
178172
},
179173
);
180174

@@ -236,14 +230,14 @@ sub index_favorites {
236230
);
237231

238232
my $files = $self->es->scroll_helper(
239-
index => $self->index->name,
240-
type => 'file',
241-
search_type => 'scan',
242-
scroll => '15s',
243-
fields => [qw< id >],
244-
size => 500,
245-
body => {
246-
query => { term => { distribution => $dist } }
233+
index => $self->index->name,
234+
type => 'file',
235+
scroll => '15s',
236+
fields => [qw< id >],
237+
size => 500,
238+
body => {
239+
query => { term => { distribution => $dist } },
240+
sort => '_doc',
247241
},
248242
);
249243

lib/MetaCPAN/Script/Latest.pm

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,23 @@ sub reindex {
265265
$release->put unless ( $self->dry_run );
266266

267267
# Get all the files for the release.
268-
my $scroll = $self->index->type("file")->search_type('scan')->filter( {
269-
bool => {
270-
must => [
271-
{ term => { 'release' => $source->{release} } },
272-
{ term => { 'author' => $source->{author} } }
273-
]
274-
}
275-
} )->size(100)->source( [ 'status', 'file' ] )->raw->scroll;
268+
my $scroll = $self->es->scroll_helper(
269+
index => $self->index->name,
270+
type => 'file',
271+
size => 100,
272+
body => {
273+
query => {
274+
bool => {
275+
must => [
276+
{ term => { 'release' => $source->{release} } },
277+
{ term => { 'author' => $source->{author} } },
278+
],
279+
},
280+
},
281+
_source => [ 'status', 'file' ],
282+
sort => '_doc',
283+
},
284+
);
276285

277286
while ( my $row = $scroll->next ) {
278287
my $source = $row->{_source};

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,17 @@ sub _copy_slice {
411411
my ( $self, $query, $index, $type ) = @_;
412412

413413
my $scroll = $self->es->scroll_helper(
414-
search_type => 'scan',
415-
size => 250,
416-
scroll => '10m',
417-
index => $self->index->name,
418-
type => $type,
419-
body => {
414+
size => 250,
415+
scroll => '10m',
416+
index => $self->index->name,
417+
type => $type,
418+
body => {
420419
query => {
421420
filtered => {
422421
query => $query
423422
}
424-
}
423+
},
424+
sort => '_doc',
425425
},
426426
);
427427

@@ -453,12 +453,14 @@ sub empty_type {
453453
);
454454

455455
my $scroll = $self->es->scroll_helper(
456-
search_type => 'scan',
457-
size => 250,
458-
scroll => '10m',
459-
index => $self->index->name,
460-
type => $type,
461-
body => { query => { match_all => {} } },
456+
size => 250,
457+
scroll => '10m',
458+
index => $self->index->name,
459+
type => $type,
460+
body => {
461+
query => { match_all => {} },
462+
sort => '_doc',
463+
},
462464
);
463465

464466
my @ids;

lib/MetaCPAN/Script/Suggest.pm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ sub _update_slice {
6363
my ( $self, $range ) = @_;
6464

6565
my $files = $self->es->scroll_helper(
66-
index => $self->index->name,
67-
type => 'file',
68-
search_type => 'scan',
69-
scroll => '5m',
70-
fields => [qw< id documentation >],
71-
size => 500,
72-
body => {
66+
index => $self->index->name,
67+
type => 'file',
68+
scroll => '5m',
69+
fields => [qw< id documentation >],
70+
size => 500,
71+
body => {
7372
query => {
7473
bool => {
7574
must => [
7675
{ exists => { field => "documentation" } }, $range
7776
],
78-
}
79-
}
77+
},
78+
},
79+
sort => '_doc',
8080
},
8181
);
8282

lib/MetaCPAN/Script/Watcher.pm

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ sub backpan_changes {
109109
filter => { term => { status => 'backpan' } }
110110
}
111111
},
112-
}
113-
}
112+
},
113+
},
114+
sort => '_doc',
114115
}
115116
} );
116117
my @changes;
@@ -183,13 +184,12 @@ sub reindex_release {
183184

184185
my $es = $self->es;
185186
my $scroll = $es->scroll_helper( {
186-
index => $self->index->name,
187-
type => 'file',
188-
scroll => '1m',
189-
size => 1000,
190-
search_type => 'scan',
191-
fields => [ '_parent', '_source' ],
192-
body => {
187+
index => $self->index->name,
188+
type => 'file',
189+
scroll => '1m',
190+
size => 1000,
191+
fields => [ '_parent', '_source' ],
192+
body => {
193193
query => {
194194
filtered => {
195195
query => { match_all => {} },
@@ -208,8 +208,9 @@ sub reindex_release {
208208
]
209209
}
210210
}
211-
}
212-
}
211+
},
212+
sort => '_doc',
213+
},
213214
} );
214215
return if ( $self->dry_run );
215216

0 commit comments

Comments
 (0)