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.
43 lines
667 B
43 lines
667 B
10 years ago
|
|
||
|
/**
|
||
|
|
||
|
query must be an array of hashes, structured like so:
|
||
|
|
||
|
{
|
||
|
_index: 'myindex',
|
||
|
_type: 'mytype',
|
||
|
_id: 'myid'
|
||
|
}
|
||
|
|
||
|
**/
|
||
|
|
||
|
function service( backend, query, cb ){
|
||
|
|
||
|
// backend command
|
||
|
var cmd = {
|
||
|
body: {
|
||
|
docs: query
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// query new backend
|
||
|
backend().client.mget( cmd, function( err, data ){
|
||
|
|
||
|
// handle backend errors
|
||
|
if( err ){ return cb( err ); }
|
||
|
|
||
|
// map returned documents
|
||
|
var docs = [];
|
||
|
if( data && Array.isArray(data.docs) ){
|
||
|
docs = data.docs.map( function( doc ){
|
||
|
return doc._source;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// fire callback
|
||
|
return cb( null, docs );
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
module.exports = service;
|