Skip to content

Commit 8bbdd3e

Browse files
authored
Merge pull request #1272 from metacpan/haarg/es5-query-fixes
update many queries for newer elasticsearch
2 parents 224ea14 + 39e68d7 commit 8bbdd3e

29 files changed

+542
-527
lines changed

docs/API-docs.md

Lines changed: 103 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,24 @@ dependency.
174174

175175
```sh
176176
curl -XPOST https://fastapi.metacpan.org/v1/release/_search -d '{
177-
"size": 5000,
178-
"fields": [ "distribution" ],
179-
"filter": {
180-
"and": [
181-
{ "term": { "dependency.module": "MooseX::NonMoose" } },
182-
{ "term": {"maturity": "released"} },
183-
{ "term": {"status": "latest"} }
184-
]
185-
}
177+
"size" : 5000,
178+
"fields" : [ "distribution" ],
179+
"query" : {
180+
"bool" : {
181+
"must" : [
182+
{ "term" : { "dependency.module" : "MooseX::NonMoose" } },
183+
{ "term" : { "maturity" : "released" } },
184+
{ "term" : { "status" : "latest" } }
185+
]
186+
}
187+
}
186188
}'
187189
```
188190

189-
_Note it is also possible to use these queries in GET requests (useful for cross-domain JSONP requests) by appropriately encoding the JSON query into the `source` parameter of the URL. For example the query above [would become](https://fastapi.metacpan.org/v1/release/_search?source=%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%2C%22size%22%3A5000%2C%22fields%22%3A%5B%22distribution%22%5D%2C%22filter%22%3A%7B%22and%22%3A%5B%7B%22term%22%3A%7B%22release.dependency.module%22%3A%22MooseX%3A%3ANonMoose%22%7D%7D%2C%7B%22term%22%3A%7B%22release.maturity%22%3A%22released%22%7D%7D%2C%7B%22term%22%3A%7B%22release.status%22%3A%22latest%22%7D%7D%5D%7D%7D):_
191+
_Note it is also possible to use these queries in GET requests (useful for cross-domain JSONP requests) by appropriately encoding the JSON query into the `source` parameter of the URL. For example the query above [would become](https://fastapi.metacpan.org/v1/release/_search?source=%7B%0A%20%20%20%20%22size%22%20%3A%205000%2C%0A%20%20%20%20%22fields%22%20%3A%20%5B%20%22distribution%22%20%5D%2C%0A%20%20%20%20%22query%22%20%3A%20%7B%0A%20%20%20%20%20%20%20%20%22bool%22%20%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22must%22%20%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22dependency.module%22%20%3A%20%22MooseX%3A%3ANonMoose%22%20%7D%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22maturity%22%20%3A%20%22released%22%20%7D%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22status%22%20%3A%20%22latest%22%20%7D%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D):_
190192

191193
```
192-
curl 'https://fastapi.metacpan.org/v1/release/_search?source=%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%2C%22size%22%3A5000%2C%22fields%22%3A%5B%22distribution%22%5D%2C%22filter%22%3A%7B%22and%22%3A%5B%7B%22term%22%3A%7B%22release.dependency.module%22%3A%22MooseX%3A%3ANonMoose%22%7D%7D%2C%7B%22term%22%3A%7B%22release.maturity%22%3A%22released%22%7D%7D%2C%7B%22term%22%3A%7B%22release.status%22%3A%22latest%22%7D%7D%5D%7D%7D'
194+
curl 'https://fastapi.metacpan.org/v1/release/_search?source=%7B%0A%20%20%20%20%22size%22%20%3A%205000%2C%0A%20%20%20%20%22fields%22%20%3A%20%5B%20%22distribution%22%20%5D%2C%0A%20%20%20%20%22query%22%20%3A%20%7B%0A%20%20%20%20%20%20%20%20%22bool%22%20%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22must%22%20%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22dependency.module%22%20%3A%20%22MooseX%3A%3ANonMoose%22%20%7D%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22maturity%22%20%3A%20%22released%22%20%7D%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22term%22%20%3A%20%7B%20%22status%22%20%3A%20%22latest%22%20%7D%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D'
193195
```
194196

195197
### [The size of the CPAN unpacked](https://github.com/metacpan/metacpan-examples/blob/master/scripts/file/5-size-of-cpan.pl)
@@ -199,64 +201,68 @@ curl 'https://fastapi.metacpan.org/v1/release/_search?source=%7B%22query%22%3A%7
199201

200202
```sh
201203
curl -XPOST https://fastapi.metacpan.org/v1/release/_search?size=100 -d '{
202-
"query": {
203-
"range" : {
204-
"date" : {
205-
"gte" : "2010-06-05T00:00:00",
206-
"lte" : "2011-06-05T00:00:00"
204+
"query" : {
205+
"range" : {
206+
"date" : {
207+
"gte" : "2010-06-05T00:00:00",
208+
"lte" : "2011-06-05T00:00:00"
209+
}
207210
}
208-
}
209-
},
210-
"fields": ["license", "name", "distribution", "date", "version_numified"]
211+
},
212+
"fields": [ "license", "name", "distribution", "date", "version_numified" ]
211213
}'
212214
```
213215

214216
### Aggregate by license:
215217

216218
```sh
217219
curl -XPOST https://fastapi.metacpan.org/v1/release/_search -d '{
218-
"query": {
219-
"match_all": {}
220+
"query" : {
221+
"match_all" : {}
220222
},
221-
"aggs": {
222-
"license": {
223-
"terms": {
224-
"field": "license"
223+
"aggs" : {
224+
"license" : {
225+
"terms" : {
226+
"field" : "license"
225227
}
226228
}
227229
},
228-
"size": 0
230+
"size" : 0
229231
}'
230232
```
231233

232234
### Most used file names in the root directory of releases:
233235

234236
```sh
235237
curl -XPOST https://fastapi.metacpan.org/v1/file/_search -d '{
236-
"query": { "filtered":{"query":{"match_all":{}},"filter":{"term":{"level":0}}}
237-
},
238-
"aggs": {
239-
"license": {
240-
"terms": {
241-
"size":100,
242-
"field":"name"
243-
} } },
244-
"size":0
238+
"query" : {
239+
"term" : { "level" : 0 }
240+
},
241+
"aggs" : {
242+
"license" : {
243+
"terms" : {
244+
"size" : 100,
245+
"field" : "name"
246+
}
247+
}
248+
},
249+
"size" : 0
245250
}'
246251
```
247252

248253
### Find all releases that contain a particular version of a module:
249254

250255
```sh
251256
curl -XPOST https://fastapi.metacpan.org/v1/file/_search -d '{
252-
"query": { "filtered":{
253-
"query":{"match_all":{}},
254-
"filter":{"and":[
255-
{"term":{"module.name":"DBI::Profile"}},
256-
{"term":{"module.version":"2.014123"}}
257-
]}
258-
}},
259-
"fields":["release"]
257+
"query" : {
258+
"bool" : {
259+
"must" : [
260+
{ "term" : { "module.name" : "DBI::Profile" } },
261+
{ "term" : { "module.version" : "2.014123" } }
262+
]
263+
}
264+
},
265+
"fields" : [ "release" ]
260266
}'
261267
```
262268

@@ -277,50 +283,61 @@ Note that "size" should be the number of distributions you are looking for.
277283
```sh
278284
lynx --dump --post_data https://fastapi.metacpan.org/v1/release/_search <<EOL
279285
{
280-
"query" : { "terms" : { "distribution" : [
281-
"Mojolicious",
282-
"MetaCPAN-API",
283-
"DBIx-Class"
284-
] } },
285-
"filter" : { "term" : { "status" : "latest" } },
286+
"query" : {
287+
"bool" : {
288+
"must" : [
289+
{
290+
"terms" : {
291+
"distribution" : [
292+
"Mojolicious",
293+
"MetaCPAN-API",
294+
"DBIx-Class"
295+
]
296+
}
297+
},
298+
{ "term" : { "status" : "latest" } }
299+
]
300+
}
301+
},
286302
"fields" : [ "distribution", "version" ],
287-
"size" : 3
303+
"size" : 3
288304
}
289305
EOL
290306
```
291307

292308
### Get a list of all files where the directory is false and the path is blank
293309
```sh
294310
curl -XPOST https://fastapi.metacpan.org/v1/file/_search -d '{
295-
"query": {
296-
"match_all": {}
297-
},
298-
"size": 1000,
299-
"fields": [ "name", "status", "directory", "path", "distribution" ],
300-
"filter": {
301-
"and": [
302-
{ "term": { "directory": false } }, { "term" : { "path" : "" } }
303-
]
304-
}
311+
"query" : {
312+
"bool" : {
313+
"must" : [
314+
{ "term" : { "directory" : false } },
315+
{ "term" : { "path" : "" } }
316+
]
317+
}
318+
},
319+
"size" : 1000,
320+
"fields" : [ "name", "status", "directory", "path", "distribution" ],
305321
}'
306322
```
307323

308324
### List releases which have an email address for a bugtracker, but not an url
309325
```sh
310326
curl -XPOST https://fastapi.metacpan.org/v1/release/_search -d '{
311-
"query": {
312-
"match_all": {}
313-
},
314-
"size": 10,
315-
"fields": [ "name", "resources.bugtracker.mailto" ],
316-
"filter": {
317-
"and": [
318-
{ "term": {"maturity": "released"} },
319-
{ "term": {"status": "latest"} },
320-
{ "exists" : { "field" : "resources.bugtracker.mailto" } },
321-
{ "missing" : { "field" : "resources.bugtracker.web" } }
322-
]
323-
}
327+
"query" : {
328+
"bool" : {
329+
"must" : [
330+
{ "term" : {"maturity" : "released"} },
331+
{ "term" : {"status" : "latest"} },
332+
{ "exists" : { "field" : "resources.bugtracker.mailto" } }
333+
],
334+
"must_not" : [
335+
{ "exists" : { "field" : "resources.bugtracker.web" } }
336+
]
337+
}
338+
},
339+
"size": 10,
340+
"fields": [ "name", "resources.bugtracker.mailto" ],
324341
}'
325342
```
326343

@@ -330,18 +347,19 @@ curl -XPOST https://fastapi.metacpan.org/v1/release/_search -d '{
330347
### Search the current PDL documentation for the string `axisvals`
331348
```sh
332349
curl -XPOST https://fastapi.metacpan.org/v1/file/_search -d '{
333-
"query" : { "filtered" : {
334-
"query" : {
335-
"query_string" : {
336-
"query" : "axisvals",
337-
"fields" : [ "pod.analyzed", "module.name" ] }
338-
},
339-
"filter" : { "and" : [
340-
{ "term" : { "distribution" : "PDL" } },
341-
{ "term" : { "status" : "latest" } }
342-
]}
343-
}},
350+
"query" : {
351+
"bool" : {
352+
"must" : [
353+
"query_string" : {
354+
"query" : "axisvals",
355+
"fields" : [ "pod.analyzed", "module.name" ]
356+
},
357+
{ "term" : { "distribution" : "PDL" } },
358+
{ "term" : { "status" : "latest" } }
359+
]
360+
}
361+
},
344362
"fields" : [ "documentation", "abstract", "module.name" ],
345363
"size" : 20
346-
}'
364+
}'
347365
```

lib/MetaCPAN/Document/Distribution.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ has river => (
4040
sub releases {
4141
my $self = shift;
4242
return $self->index->type("release")
43-
->filter( { term => { "distribution" => $self->name } } );
43+
->query( { term => { "distribution" => $self->name } } );
4444
}
4545

4646
sub set_first_release {

0 commit comments

Comments
 (0)