Skip to content

Commit 8cc107e

Browse files
authored
Merge pull request #61 from metacpan/mickey/es_syntax
ES syntax - make compatible with newer versions
2 parents 92c0858 + 4c082b0 commit 8cc107e

File tree

5 files changed

+111
-118
lines changed

5 files changed

+111
-118
lines changed

bin/check.pl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@
4242
fields => [
4343
qw< name release author distribution version authorized indexed maturity date >
4444
],
45-
query => { match_all => {} },
46-
filter => {
47-
and => [
48-
{ term => { 'module.name' => $pkg } },
49-
{ term => { authorized => 'true' } },
50-
{ term => { maturity => 'released' } },
51-
],
45+
query => {
46+
bool => {
47+
must => [
48+
{ term => { 'module.name' => $pkg } },
49+
{ term => { authorized => 'true' } },
50+
{ term => { maturity => 'released' } },
51+
],
52+
},
5253
},
5354
);
5455
my @files = @{ $results->{hits}{hits} };
@@ -58,12 +59,13 @@
5859
my $release_results = $es_release->search(
5960
size => 1,
6061
fields => [qw< name status authorized version id date >],
61-
query => { match_all => {} },
62-
filter => {
63-
and => [
64-
{ term => { name => $file->{fields}{release} } },
65-
{ term => { status => 'latest' } },
66-
],
62+
query => {
63+
bool => {
64+
must => [
65+
{ term => { name => $file->{fields}{release} } },
66+
{ term => { status => 'latest' } },
67+
],
68+
},
6769
},
6870
);
6971

@@ -79,11 +81,12 @@
7981
size => 1,
8082
fields =>
8183
[qw< name status authorized version id date >],
82-
query => { match_all => {} },
83-
filter => {
84-
and => [ {
85-
term => { name => $file->{fields}{release} }
86-
} ]
84+
query => {
85+
bool => {
86+
must => [
87+
{ term => { name => $file->{fields}{release} } },
88+
],
89+
},
8790
},
8891
);
8992

bin/latest.pl

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ()
8888
# 'file' type records where the module.name matches the
8989
# distribution name and which are released &
9090
# indexed (the 'leading' module)
91-
my $q_body = _body_filtered_query($filter);
91+
my $q_body = _body_query($filter);
9292

9393
my $scroll = $es->scroll(
9494
body => $q_body,
@@ -219,31 +219,26 @@ ($filter)
219219
return \@module_filters;
220220
}
221221

222-
sub _body_filtered_query ($filter) {
222+
sub _body_query ($filter) {
223223
return +{
224224
query => {
225-
filtered => {
226-
query => { match_all => {} },
227-
filter => {
228-
bool => {
229-
must => [
230-
{
231-
nested => {
232-
path => 'module',
233-
query => { bool => { must => $filter } }
234-
}
235-
},
236-
{ term => { 'maturity' => 'released' } },
237-
],
238-
must_not => [
239-
{ term => { status => 'backpan' } },
240-
{ term => { distribution => 'perl' } }
241-
]
242-
}
243-
},
244-
},
245-
}
246-
};
225+
bool => {
226+
must => [
227+
{
228+
nested => {
229+
path => 'module',
230+
query => { bool => { must => $filter } }
231+
}
232+
},
233+
{ term => { 'maturity' => 'released' } },
234+
],
235+
must_not => [
236+
{ term => { status => 'backpan' } },
237+
{ term => { distribution => 'perl' } }
238+
]
239+
}
240+
},
241+
},
247242
}
248243

249244
sub _queue_latest ( $dist = $distribution ) {
@@ -326,19 +321,14 @@ ( $bulk, $source, $status )
326321
my $scroll = $es_file->scroll(
327322
body => {
328323
query => {
329-
filtered => {
330-
query => { match_all => {} },
331-
filter => {
332-
bool => {
333-
must => [
334-
{
335-
term =>
336-
{ 'release' => $source->{release} }
337-
},
338-
{ term => { 'author' => $source->{author} } },
339-
],
324+
bool => {
325+
must => [
326+
{
327+
term =>
328+
{ 'release' => $source->{release} }
340329
},
341-
},
330+
{ term => { 'author' => $source->{author} } },
331+
],
342332
},
343333
},
344334
fields => [qw< name >],

bin/release.pl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,18 @@ ($document)
426426
my $count = $es->search(
427427
search_type => 'count',
428428
body => {
429-
query => { match_all => {} },
430-
filter => {
431-
and => [
432-
{ term => { distribution => $document->{distribution} } },
433-
{
434-
range => {
435-
version_numified =>
429+
query => {
430+
bool => {
431+
must => [
432+
{ term => { distribution => $document->{distribution} } },
433+
{
434+
range => {
435+
version_numified =>
436436
{ 'lt' => $document->{version_numified} }
437+
},
437438
},
438-
}
439-
],
439+
],
440+
},
440441
},
441442
},
442443
)->{hits}{total};

bin/tickets.pl

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,30 @@ ()
124124
my $scroll_release = $es_release->scroll(
125125
body => {
126126
query => {
127-
and => [
128-
{ term => { status => 'latest' } },
129-
{
130-
or => [
131-
{
132-
prefix => {
133-
"resources.bugtracker.web" =>
134-
'http://github.com/'
135-
}
127+
bool => {
128+
must => [
129+
{ term => { status => 'latest' } },
130+
{
131+
bool => {
132+
should => [
133+
{
134+
prefix => {
135+
"resources.bugtracker.web" =>
136+
'http://github.com/'
137+
},
138+
},
139+
{
140+
prefix => {
141+
"resources.bugtracker.web" =>
142+
'https://github.com/'
143+
},
144+
},
145+
],
136146
},
137-
{
138-
prefix => {
139-
"resources.bugtracker.web" =>
140-
'https://github.com/'
141-
}
142-
},
143-
],
144-
}
145-
],
146-
}
147+
},
148+
],
149+
},
150+
},
147151
},
148152
);
149153

bin/watcher.pl

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,13 @@ ()
9898
fields => [qw< author archive >],
9999
body => {
100100
query => {
101-
filtered => {
102-
query => { match_all => {} },
103-
filter => {
104-
not => {
105-
filter => { term => { status => 'backpan' } }
106-
}
107-
}
108-
}
109-
}
110-
}
101+
bool => {
102+
must_not => [
103+
{ term => { status => 'backpan' } }
104+
],
105+
},
106+
},
107+
},
111108
);
112109

113110
my @changes;
@@ -168,14 +165,15 @@ ($info)
168165
my $scroll_release = $es_release->scroll(
169166
scroll => '1m',
170167
body => {
171-
query => { match_all => {} },
172-
filter => {
173-
and => [
174-
{ term => { author => $info->cpanid } },
175-
{ term => { archive => $info->filename } },
176-
]
168+
query => {
169+
bool => {
170+
must => [
171+
{ term => { author => $info->cpanid } },
172+
{ term => { archive => $info->filename } },
173+
],
174+
},
177175
},
178-
}
176+
},
179177
);
180178

181179
return $scroll_release->next;
@@ -193,25 +191,22 @@ ($release)
193191
fields => [qw< _parent _source >],
194192
body => {
195193
query => {
196-
filtered => {
197-
query => { match_all => {} },
198-
filter => {
199-
and => [
200-
{
201-
term => {
202-
release => $release->{_source}{name}
203-
}
204-
},
205-
{
206-
term => {
207-
author => $release->{_source}{author}
208-
}
209-
},
210-
]
211-
}
212-
}
213-
}
214-
}
194+
bool => {
195+
must => [
196+
{
197+
term => {
198+
release => $release->{_source}{name}
199+
}
200+
},
201+
{
202+
term => {
203+
author => $release->{_source}{author}
204+
}
205+
},
206+
],
207+
},
208+
},
209+
},
215210
} );
216211
return if $dry_run;
217212

0 commit comments

Comments
 (0)