mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
540 B
30 lines
540 B
|
|
/** |
|
|
|
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; |