viewer/multies.js
// Go thru all the ES nodes and perform the same query and return the bodies for further processing
Go thru all the ES nodes and perform the same query and return the bodies for further processing
Go thru all the ES nodes and perform the same query and return the bodies for further processing
function simpleGather (req, res, bodies, doneCb) {
  var nodes = getActiveNodes();
  async.map(nodes, (node, asyncCb) => {
    var result = '';
    var url = node2Url(node) + req.url;
    var prefix = node2Prefix(node);
    url = url.replace(/MULTIPREFIX_/g, prefix);
    var info = URL.parse(url);
    info.method = req.method;
    var client;
    if (url.match(/^https:/)) {
      info.agent = httpsAgent;
      client = https;
    } else {
      info.agent = httpAgent;
      client = http;
    }
    var preq = client.request(info, (pres) => {
      pres.on('data', (chunk) => {
        result += chunk.toString();
      });
      pres.on('end', () => {
        if (result.length) {
          result = result.replace(new RegExp('(index":\\s*|[,{]|  )"' + prefix + '(sessions2|sessions|stats|dstats|sequence|files|users|history)', 'g'), '$1"MULTIPREFIX_$2');
          result = result.replace(new RegExp('(index":\\s*)"' + prefix + '(fields_v[1-4])"', 'g'), '$1"MULTIPREFIX_$2"');
          result = JSON.parse(result);
        } else {
          result = {};
        }
        result._node = node;
        asyncCb(null, result);
      });
    });
    preq.setHeader('content-type', 'application/json');
    if (req.headers['x-opaque-id'] !== undefined) {
      preq.setHeader('X-Opaque-Id', req.headers['x-opaque-id']);
    }
    if (req._body) {
      if (bodies && bodies[node]) {
        preq.end(bodies[node]);
      } else {
        preq.end(req.body);
      }
    }
    preq.on('error', (e) => {
      console.log('Request error with node', node, e);
    });
    preq.end();
  }, doneCb);
}
function simpleGather ( req , res , bodies , doneCb ) { var nodes = getActiveNodes ( ) ; async . map ( nodes , ( node , asyncCb ) => { var result = '' ; var url = node2Url ( node ) + req . url ; var prefix = node2Prefix ( node ) ; url = url . replace ( / MULTIPREFIX_ / g , prefix ) ; var info = URL . parse ( url ) ; info . method = req . method ; var client ; if ( url . match ( / ^https: / ) ) { info . agent = httpsAgent ; client = https ; } else { info . agent = httpAgent ; client = http ; } var preq = client . request ( info , ( pres ) => { pres . on ( 'data' , ( chunk ) => { result += chunk . toString ( ) ; } ) ; pres . on ( 'end' , ( ) => { if ( result . length ) { result = result . replace ( new RegExp ( '(index":\\s*|[,{]|  )"' + prefix + '(sessions2|sessions|stats|dstats|sequence|files|users|history)' , 'g' ) , '$1"MULTIPREFIX_$2' ) ; result = result . replace ( new RegExp ( '(index":\\s*)"' + prefix + '(fields_v[1-4])"' , 'g' ) , '$1"MULTIPREFIX_$2"' ) ; result = JSON . parse ( result ) ; } else { result = { } ; } result . _node = node ; asyncCb ( null , result ) ; } ) ; } ) ; preq . setHeader ( 'content-type' , 'application/json' ) ; if ( req . headers [ 'x-opaque-id' ] !== undefined ) { preq . setHeader ( 'X-Opaque-Id' , req . headers [ 'x-opaque-id' ] ) ; } if ( req . _body ) { if ( bodies && bodies [ node ] ) { preq . end ( bodies [ node ] ) ; } else { preq . end ( req . body ) ; } } preq . on ( 'error' , ( e ) => { console . log ( 'Request error with node' , node , e ) ; } ) ; preq . end ( ) ; } , doneCb ) ; }
Go thru all the ES nodes and perform the same query and return the bodies for further processing
Go thru all the ES nodes and perform the same query and return the bodies for further processing