|
|
|
@ -4,6 +4,8 @@ const searchService = require('../service/search');
|
|
|
|
|
const logger = require('pelias-logger').get('api'); |
|
|
|
|
const logging = require( '../helper/logging' ); |
|
|
|
|
const retry = require('retry'); |
|
|
|
|
const Debug = require('../helper/debug'); |
|
|
|
|
const debugLog = new Debug('controller:search_with_ids'); |
|
|
|
|
|
|
|
|
|
function isRequestTimeout(err) { |
|
|
|
|
return _.get(err, 'status') === 408; |
|
|
|
@ -15,6 +17,7 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
return next(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const initialTime = debugLog.beginTimer(req); |
|
|
|
|
const cleanOutput = _.cloneDeep(req.clean); |
|
|
|
|
if (logging.isDNT(req)) { |
|
|
|
|
logging.removeFields(cleanOutput); |
|
|
|
@ -26,6 +29,7 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
|
|
|
|
|
// if there's no query to call ES with, skip the service
|
|
|
|
|
if (_.isUndefined(renderedQuery)) { |
|
|
|
|
debugLog.stopTimer(req, initialTime, 'No query to call ES with. Skipping'); |
|
|
|
|
return next(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -49,6 +53,7 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
logger.debug( '[ES req]', cmd ); |
|
|
|
|
debugLog.push(req, {ES_req: cmd}); |
|
|
|
|
|
|
|
|
|
operation.attempt((currentAttempt) => { |
|
|
|
|
// query elasticsearch
|
|
|
|
@ -58,6 +63,7 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
// only consider for status 408 (request timeout)
|
|
|
|
|
if (isRequestTimeout(err) && operation.retry(err)) { |
|
|
|
|
logger.info(`request timed out on attempt ${currentAttempt}, retrying`); |
|
|
|
|
debugLog.stopTimer(req, initialTime, 'request timed out, retrying'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -95,6 +101,11 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
logger.info(messageParts.join(' ')); |
|
|
|
|
debugLog.push(req, {queryType: { |
|
|
|
|
[renderedQuery.type] : { |
|
|
|
|
es_result_count: parseInt(messageParts[2].slice(17, -1)) |
|
|
|
|
} |
|
|
|
|
}}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -102,7 +113,7 @@ function setup( apiConfig, esclient, query, should_execute ){
|
|
|
|
|
logger.debug('[ES response]', docs); |
|
|
|
|
next(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
debugLog.stopTimer(req, initialTime); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|