query_def.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. export const metricAggTypes = [
  4. { text: 'Count', value: 'count', requiresField: false },
  5. {
  6. text: 'Average',
  7. value: 'avg',
  8. requiresField: true,
  9. supportsInlineScript: true,
  10. supportsMissing: true,
  11. },
  12. {
  13. text: 'Sum',
  14. value: 'sum',
  15. requiresField: true,
  16. supportsInlineScript: true,
  17. supportsMissing: true,
  18. },
  19. {
  20. text: 'Max',
  21. value: 'max',
  22. requiresField: true,
  23. supportsInlineScript: true,
  24. supportsMissing: true,
  25. },
  26. {
  27. text: 'Min',
  28. value: 'min',
  29. requiresField: true,
  30. supportsInlineScript: true,
  31. supportsMissing: true,
  32. },
  33. {
  34. text: 'Extended Stats',
  35. value: 'extended_stats',
  36. requiresField: true,
  37. supportsMissing: true,
  38. supportsInlineScript: true,
  39. },
  40. {
  41. text: 'Percentiles',
  42. value: 'percentiles',
  43. requiresField: true,
  44. supportsMissing: true,
  45. supportsInlineScript: true,
  46. },
  47. {
  48. text: 'Unique Count',
  49. value: 'cardinality',
  50. requiresField: true,
  51. supportsMissing: true,
  52. },
  53. {
  54. text: 'Moving Average',
  55. value: 'moving_avg',
  56. requiresField: false,
  57. isPipelineAgg: true,
  58. minVersion: 2,
  59. },
  60. {
  61. text: 'Derivative',
  62. value: 'derivative',
  63. requiresField: false,
  64. isPipelineAgg: true,
  65. minVersion: 2,
  66. },
  67. { text: 'Raw Document', value: 'raw_document', requiresField: false },
  68. ];
  69. export const bucketAggTypes = [
  70. { text: 'Terms', value: 'terms', requiresField: true },
  71. { text: 'Filters', value: 'filters' },
  72. { text: 'Geo Hash Grid', value: 'geohash_grid', requiresField: true },
  73. { text: 'Date Histogram', value: 'date_histogram', requiresField: true },
  74. { text: 'Histogram', value: 'histogram', requiresField: true },
  75. ];
  76. export const orderByOptions = [
  77. { text: 'Doc Count', value: '_count' },
  78. { text: 'Term value', value: '_term' },
  79. ];
  80. export const orderOptions = [
  81. { text: 'Top', value: 'desc' },
  82. { text: 'Bottom', value: 'asc' },
  83. ];
  84. export const sizeOptions = [
  85. { text: 'No limit', value: '0' },
  86. { text: '1', value: '1' },
  87. { text: '2', value: '2' },
  88. { text: '3', value: '3' },
  89. { text: '5', value: '5' },
  90. { text: '10', value: '10' },
  91. { text: '15', value: '15' },
  92. { text: '20', value: '20' },
  93. ];
  94. export const extendedStats = [
  95. { text: 'Avg', value: 'avg' },
  96. { text: 'Min', value: 'min' },
  97. { text: 'Max', value: 'max' },
  98. { text: 'Sum', value: 'sum' },
  99. { text: 'Count', value: 'count' },
  100. { text: 'Std Dev', value: 'std_deviation' },
  101. { text: 'Std Dev Upper', value: 'std_deviation_bounds_upper' },
  102. { text: 'Std Dev Lower', value: 'std_deviation_bounds_lower' },
  103. ];
  104. export const intervalOptions = [
  105. { text: 'auto', value: 'auto' },
  106. { text: '10s', value: '10s' },
  107. { text: '1m', value: '1m' },
  108. { text: '5m', value: '5m' },
  109. { text: '10m', value: '10m' },
  110. { text: '20m', value: '20m' },
  111. { text: '1h', value: '1h' },
  112. { text: '1d', value: '1d' },
  113. ];
  114. export const movingAvgModelOptions = [
  115. { text: 'Simple', value: 'simple' },
  116. { text: 'Linear', value: 'linear' },
  117. { text: 'Exponentially Weighted', value: 'ewma' },
  118. { text: 'Holt Linear', value: 'holt' },
  119. { text: 'Holt Winters', value: 'holt_winters' },
  120. ];
  121. export const pipelineOptions = {
  122. moving_avg: [
  123. { text: 'window', default: 5 },
  124. { text: 'model', default: 'simple' },
  125. { text: 'predict', default: undefined },
  126. { text: 'minimize', default: false },
  127. ],
  128. derivative: [{ text: 'unit', default: undefined }],
  129. };
  130. export const movingAvgModelSettings = {
  131. simple: [],
  132. linear: [],
  133. ewma: [{ text: 'Alpha', value: 'alpha', default: undefined }],
  134. holt: [
  135. { text: 'Alpha', value: 'alpha', default: undefined },
  136. { text: 'Beta', value: 'beta', default: undefined },
  137. ],
  138. holt_winters: [
  139. { text: 'Alpha', value: 'alpha', default: undefined },
  140. { text: 'Beta', value: 'beta', default: undefined },
  141. { text: 'Gamma', value: 'gamma', default: undefined },
  142. { text: 'Period', value: 'period', default: undefined },
  143. { text: 'Pad', value: 'pad', default: undefined, isCheckbox: true },
  144. ],
  145. };
  146. export function getMetricAggTypes(esVersion) {
  147. return _.filter(metricAggTypes, function(f) {
  148. if (f.minVersion) {
  149. return f.minVersion <= esVersion;
  150. } else {
  151. return true;
  152. }
  153. });
  154. }
  155. export function getPipelineOptions(metric) {
  156. if (!isPipelineAgg(metric.type)) {
  157. return [];
  158. }
  159. return pipelineOptions[metric.type];
  160. }
  161. export function isPipelineAgg(metricType) {
  162. if (metricType) {
  163. var po = pipelineOptions[metricType];
  164. return po !== null && po !== undefined;
  165. }
  166. return false;
  167. }
  168. export function getPipelineAggOptions(targets) {
  169. var result = [];
  170. _.each(targets.metrics, function(metric) {
  171. if (!isPipelineAgg(metric.type)) {
  172. result.push({ text: describeMetric(metric), value: metric.id });
  173. }
  174. });
  175. return result;
  176. }
  177. export function getMovingAvgSettings(model, filtered) {
  178. var filteredResult = [];
  179. if (filtered) {
  180. _.each(movingAvgModelSettings[model], function(setting) {
  181. if (!setting.isCheckbox) {
  182. filteredResult.push(setting);
  183. }
  184. });
  185. return filteredResult;
  186. }
  187. return movingAvgModelSettings[model];
  188. }
  189. export function getOrderByOptions(target) {
  190. var metricRefs = [];
  191. _.each(target.metrics, function(metric) {
  192. if (metric.type !== 'count') {
  193. metricRefs.push({ text: describeMetric(metric), value: metric.id });
  194. }
  195. });
  196. return orderByOptions.concat(metricRefs);
  197. }
  198. export function describeOrder(order) {
  199. var def = _.find(orderOptions, { value: order });
  200. return def.text;
  201. }
  202. export function describeMetric(metric) {
  203. var def = _.find(metricAggTypes, { value: metric.type });
  204. return def.text + ' ' + metric.field;
  205. }
  206. export function describeOrderBy(orderBy, target) {
  207. var def = _.find(orderByOptions, { value: orderBy });
  208. if (def) {
  209. return def.text;
  210. }
  211. var metric = _.find(target.metrics, { id: orderBy });
  212. if (metric) {
  213. return describeMetric(metric);
  214. } else {
  215. return 'metric not found';
  216. }
  217. }