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.

59 lines
1.0 KiB

10 years ago
/**
query must be an array of hashes, structured like so:
{
_index: 'myindex',
_type: 'mytype',
_id: 'myid'
}
**/
var logger = require( 'pelias-logger' ).get( 'api' );
function service( esclient, query, cb ){
10 years ago
// elasticsearch command
10 years ago
var cmd = {
body: {
docs: query
}
};
// query elasticsearch
esclient.mget( cmd, function( err, data ){
// handle elasticsearch errors
if( err ){
logger.error( `elasticsearch error ${err}`);
return cb( err );
}
10 years ago
// map returned documents
var docs = [];
if( data && Array.isArray(data.docs) ){
docs = data.docs.filter( function( doc ){
// remove docs not actually found
return doc.found;
}).map( function( doc ){
// map metadata in to _source so we
// can serve it up to the consumer
doc._source._id = doc._id;
doc._source._type = doc._type;
10 years ago
return doc._source;
});
}
// fire callback
return cb( null, docs );
});
}
module.exports = service;