web/apps/hello-elasticsearch/js/hello-elasticsearch.js
function updateQuery() {
  let query = {};

  switch(queryTemplates.value) {
    case '0': // All raddecs
      query = {
          "size": 10,
          "query": { "match_all": {} },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '1': // Specific transmitterId
      query = {
          "size": 10,
          "query": { "term": { "transmitterId": "" } },
          "_source": [ "receiverId", "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets", "packets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '2': // Prefix transmitterId
      query = {
          "size": 10,
          "query": { "prefix": { "transmitterId": "" } },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '3': // Aggregate receiverId
      query = {
          "size": 0,
          "aggs" : {
            "receivers" : {
              "terms" : {
                "field" : "receiverId.keyword",
                "order" : { "_count" : "desc" },
                "size": 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '4': // Aggregate rec/dec/pac
      query = {
          "size": 0,
          "aggs" : {
            "numberOfReceivers" : {
              "histogram" : {
                "field" : "numberOfReceivers",
                "interval" : 1
              }
            },
            "numberOfDecodings" : {
              "histogram" : {
                "field" : "numberOfDecodings",
                "interval" : 1,
                "min_doc_count" : 1
              }
            },
            "numberOfDistinctPackets" : {
              "histogram" : {
                "field" : "numberOfDistinctPackets",
                "interval" : 1
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '5': // Auto-date histogram
      query = {
          "size": 0,
          "aggs" : {
            "periods" : {
              "auto_date_histogram" : {
                "field" : "timestamp",
                "buckets" : 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
  }
  queryBox.rows = countNumberOfLines(queryBox.value);
  parseQuery();
}
function updateQuery() {
  let query = {};

  switch(queryTemplates.value) {
    case '0': // All raddecs
      query = {
          "size": 10,
          "query": { "match_all": {} },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '1': // Specific transmitterId
      query = {
          "size": 10,
          "query": { "term": { "transmitterId": "" } },
          "_source": [ "receiverId", "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets", "packets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '2': // Prefix transmitterId
      query = {
          "size": 10,
          "query": { "prefix": { "transmitterId": "" } },
          "_source": [ "transmitterId", "transmitterIdType", "receiverId",
                       "receiverIdType", "rssi", "timestamp",
                       "numberOfDecodings", "numberOfReceivers",
                       "numberOfPackets" ]
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '3': // Aggregate receiverId
      query = {
          "size": 0,
          "aggs" : {
            "receivers" : {
              "terms" : {
                "field" : "receiverId.keyword",
                "order" : { "_count" : "desc" },
                "size": 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '4': // Aggregate rec/dec/pac
      query = {
          "size": 0,
          "aggs" : {
            "numberOfReceivers" : {
              "histogram" : {
                "field" : "numberOfReceivers",
                "interval" : 1
              }
            },
            "numberOfDecodings" : {
              "histogram" : {
                "field" : "numberOfDecodings",
                "interval" : 1,
                "min_doc_count" : 1
              }
            },
            "numberOfDistinctPackets" : {
              "histogram" : {
                "field" : "numberOfDistinctPackets",
                "interval" : 1
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
    case '5': // Auto-date histogram
      query = {
          "size": 0,
          "aggs" : {
            "periods" : {
              "auto_date_histogram" : {
                "field" : "timestamp",
                "buckets" : 12
              }
            }
          }
      };
      queryBox.value = JSON.stringify(query, null, 2);
      break;
  }
  queryBox.rows = countNumberOfLines(queryBox.value);
  parseQuery();
}
function updateQuery ( ) { let query = { } ; switch ( queryTemplates . value ) { case '0' : // All raddecs query = { "size" : 10 , "query" : { "match_all" : { } } , "_source" : [ "transmitterId" , "transmitterIdType" , "receiverId" , "receiverIdType" , "rssi" , "timestamp" , "numberOfDecodings" , "numberOfReceivers" , "numberOfPackets" ] } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; case '1' : // Specific transmitterId query = { "size" : 10 , "query" : { "term" : { "transmitterId" : "" } } , "_source" : [ "receiverId" , "receiverIdType" , "rssi" , "timestamp" , "numberOfDecodings" , "numberOfReceivers" , "numberOfPackets" , "packets" ] } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; case '2' : // Prefix transmitterId query = { "size" : 10 , "query" : { "prefix" : { "transmitterId" : "" } } , "_source" : [ "transmitterId" , "transmitterIdType" , "receiverId" , "receiverIdType" , "rssi" , "timestamp" , "numberOfDecodings" , "numberOfReceivers" , "numberOfPackets" ] } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; case '3' : // Aggregate receiverId query = { "size" : 0 , "aggs" : { "receivers" : { "terms" : { "field" : "receiverId.keyword" , "order" : { "_count" : "desc" } , "size" : 12 } } } } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; case '4' : // Aggregate rec/dec/pac query = { "size" : 0 , "aggs" : { "numberOfReceivers" : { "histogram" : { "field" : "numberOfReceivers" , "interval" : 1 } } , "numberOfDecodings" : { "histogram" : { "field" : "numberOfDecodings" , "interval" : 1 , "min_doc_count" : 1 } } , "numberOfDistinctPackets" : { "histogram" : { "field" : "numberOfDistinctPackets" , "interval" : 1 } } } } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; case '5' : // Auto-date histogram query = { "size" : 0 , "aggs" : { "periods" : { "auto_date_histogram" : { "field" : "timestamp" , "buckets" : 12 } } } } ; queryBox . value = JSON . stringify ( query , null , 2 ) ; break ; } queryBox . rows = countNumberOfLines ( queryBox . value ) ; parseQuery ( ) ; }
Update the query JSON based on the selected template
Update the query JSON based on the selected template