query_def.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. define([
  2. 'lodash'
  3. ],
  4. function (_) {
  5. 'use strict';
  6. return {
  7. metricAggTypes: [
  8. {text: "Count", value: 'count', requiresField: false},
  9. {text: "Average", value: 'avg', requiresField: true},
  10. {text: "Sum", value: 'sum', requiresField: true},
  11. {text: "Max", value: 'max', requiresField: true},
  12. {text: "Min", value: 'min', requiresField: true},
  13. {text: "Extended Stats", value: 'extended_stats', requiresField: true},
  14. {text: "Percentiles", value: 'percentiles', requiresField: true},
  15. {text: "Moving Average", value: 'moving_avg', requiresField: false },
  16. {text: "Unique Count", value: "cardinality", requiresField: true},
  17. {text: "Raw Document", value: "raw_document", requiresField: false}
  18. ],
  19. bucketAggTypes: [
  20. {text: "Terms", value: 'terms' },
  21. {text: "Filters", value: 'filters' },
  22. {text: "Date Histogram", value: 'date_histogram' },
  23. ],
  24. orderByOptions: [
  25. {text: "Doc Count", value: '_count' },
  26. {text: "Term value", value: '_term' },
  27. ],
  28. orderOptions: [
  29. {text: "Top", value: 'desc' },
  30. {text: "Bottom", value: 'asc' },
  31. ],
  32. sizeOptions: [
  33. {text: "No limit", value: '0' },
  34. {text: "1", value: '1' },
  35. {text: "2", value: '2' },
  36. {text: "3", value: '3' },
  37. {text: "5", value: '5' },
  38. {text: "10", value: '10' },
  39. {text: "15", value: '15' },
  40. {text: "20", value: '20' },
  41. ],
  42. extendedStats: [
  43. {text: 'Avg', value: 'avg'},
  44. {text: 'Min', value: 'min'},
  45. {text: 'Max', value: 'max'},
  46. {text: 'Sum', value: 'sum'},
  47. {text: 'Count', value: 'count'},
  48. {text: 'Std Dev', value: 'std_deviation'},
  49. {text: 'Std Dev Upper', value: 'std_deviation_bounds_upper'},
  50. {text: 'Std Dev Lower', value: 'std_deviation_bounds_lower'},
  51. ],
  52. intervalOptions: [
  53. {text: 'auto', value: 'auto'},
  54. {text: '10s', value: '10s'},
  55. {text: '1m', value: '1m'},
  56. {text: '5m', value: '5m'},
  57. {text: '10m', value: '10m'},
  58. {text: '20m', value: '20m'},
  59. {text: '1h', value: '1h'},
  60. {text: '1d', value: '1d'},
  61. ],
  62. pipelineAggs: ['moving_avg'],
  63. isPipelineAgg: function(metric) {
  64. if (metric.type) {
  65. return this.pipelineAggs.indexOf(metric.type) > -1;
  66. }
  67. return false;
  68. },
  69. getMovingAverageOptions: function(targets) {
  70. var self = this;
  71. var result = [];
  72. _.each(targets.metrics, function(metric) {
  73. if (metric.type !== 'moving_avg') {
  74. result.push({text: self.describeMetric(metric), value: metric.id });
  75. }
  76. });
  77. return result;
  78. },
  79. getOrderByOptions: function(target) {
  80. var self = this;
  81. var metricRefs = [];
  82. _.each(target.metrics, function(metric) {
  83. if (metric.type !== 'count') {
  84. metricRefs.push({text: self.describeMetric(metric), value: metric.id});
  85. }
  86. });
  87. return this.orderByOptions.concat(metricRefs);
  88. },
  89. describeOrder: function(order) {
  90. var def = _.findWhere(this.orderOptions, {value: order});
  91. return def.text;
  92. },
  93. describeMetric: function(metric) {
  94. var def = _.findWhere(this.metricAggTypes, {value: metric.type});
  95. return def.text + ' ' + metric.field;
  96. },
  97. describeOrderBy: function(orderBy, target) {
  98. var def = _.findWhere(this.orderByOptions, {value: orderBy});
  99. if (def) {
  100. return def.text;
  101. }
  102. var metric = _.findWhere(target.metrics, {id: orderBy});
  103. if (metric) {
  104. return this.describeMetric(metric);
  105. } else {
  106. return "metric not found";
  107. }
  108. },
  109. };
  110. });