mirror of https://github.com/pelias/api.git
Peter Johnson
10 years ago
2 changed files with 34 additions and 10 deletions
@ -0,0 +1,30 @@
|
||||
|
||||
/** |
||||
|
||||
query can be any valid ES query |
||||
|
||||
**/ |
||||
|
||||
function service( backend, cmd, cb ){ |
||||
|
||||
// query new backend
|
||||
backend().client.search( cmd, function( err, data ){ |
||||
|
||||
// handle backend errors
|
||||
if( err ){ return cb( err ); } |
||||
|
||||
// map returned documents
|
||||
var docs = []; |
||||
if( data && data.hits && data.hits.total && Array.isArray(data.hits.hits)){ |
||||
docs = data.hits.hits.map( function( hit ){ |
||||
return hit._source; |
||||
}); |
||||
} |
||||
|
||||
// fire callback
|
||||
return cb( null, docs ); |
||||
}); |
||||
|
||||
} |
||||
|
||||
module.exports = service; |
Loading…
Reference in new issue