lib/ericssonmanager.js
/**
 * Run the Minute of Hour query in Elasticsearch.
 * @param {Elasticsearch} esClient The Elasticsearch client.
 * @param {function} callback The function to call on completion.
 */
Run the Minute of Hour query in Elasticsearch.
@param {Elasticsearch} esClient The Elasticsearch client.
@param {function} callback The function to call on completion.
Run the Minute of Hour query in Elasticsearch . @param { Elasticsearch } esClient The Elasticsearch client . @param { function } callback The function to call on completion .
function queryMinuteOfHour(esClient, callback) {
  let startTimestamp = new Date(Date.now() - 3600000).getTime();
  let endTimestamp = new Date().getTime();
  let body = {
      "size": 0,
      "aggs": {
        "date": {
          "date_histogram": {
            "field": "timestamp",
            "interval": "1m"
          },
          "aggs": {
            "count": {
              "cardinality": {
                "field": "transmitterId.keyword"
              }
            }
          }
        }     
      },
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "timestamp" : {
                  "gte" : startTimestamp,
                  "lt" :  endTimestamp
                }
              }
            },
            {
              "range": {
                "rssi" : {
                  "gte" : RSSI_MIN_THRESHOLD,
                  "lt" :  RSSI_MAX_THRESHOLD
                }
              }
            }
          ]
        }
      }
  };
  let query = { index: 'raddec', body: body };
  esClient.search(query, function(err, result) {
    let data = { x: [], y: [] };
    if(err) {
     console.log('Ericsson queryMinuteOfHour error:', err);
    }
    else {
      let buckets = result.body.aggregations.date.buckets;
      buckets.forEach(function(item) {
        let timestamp = new Date(item.key).getTime();
        let count = item.count.value;
        data.x.push(timestamp);
        data.y.push(count);
      });
    }
    return callback(data);
  });
}
function queryMinuteOfHour ( esClient , callback ) { let startTimestamp = new Date ( Date . now ( ) - 3600000 ) . getTime ( ) ; let endTimestamp = new Date ( ) . getTime ( ) ; let body = { "size" : 0 , "aggs" : { "date" : { "date_histogram" : { "field" : "timestamp" , "interval" : "1m" } , "aggs" : { "count" : { "cardinality" : { "field" : "transmitterId.keyword" } } } } } , "query" : { "bool" : { "must" : [ { "range" : { "timestamp" : { "gte" : startTimestamp , "lt" : endTimestamp } } } , { "range" : { "rssi" : { "gte" : RSSI_MIN_THRESHOLD , "lt" : RSSI_MAX_THRESHOLD } } } ] } } } ; let query = { index : 'raddec' , body : body } ; esClient . search ( query , function ( err , result ) { let data = { x : [ ] , y : [ ] } ; if ( err ) { console . log ( 'Ericsson queryMinuteOfHour error:' , err ) ; } else { let buckets = result . body . aggregations . date . buckets ; buckets . forEach ( function ( item ) { let timestamp = new Date ( item . key ) . getTime ( ) ; let count = item . count . value ; data . x . push ( timestamp ) ; data . y . push ( count ) ; } ) ; } return callback ( data ) ; } ) ; }
Run the Minute of Hour query in Elasticsearch.
Run the Minute of Hour query in Elasticsearch .
// Time range is from an hour ago to now