query_def.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 = [{ text: 'Doc Count', value: '_count' }, { text: 'Term value', value: '_term' }];
  77. export const orderOptions = [{ text: 'Top', value: 'desc' }, { text: 'Bottom', value: 'asc' }];
  78. export const sizeOptions = [
  79. { text: 'No limit', value: '0' },
  80. { text: '1', value: '1' },
  81. { text: '2', value: '2' },
  82. { text: '3', value: '3' },
  83. { text: '5', value: '5' },
  84. { text: '10', value: '10' },
  85. { text: '15', value: '15' },
  86. { text: '20', value: '20' },
  87. ];
  88. export const extendedStats = [
  89. { text: 'Avg', value: 'avg' },
  90. { text: 'Min', value: 'min' },
  91. { text: 'Max', value: 'max' },
  92. { text: 'Sum', value: 'sum' },
  93. { text: 'Count', value: 'count' },
  94. { text: 'Std Dev', value: 'std_deviation' },
  95. { text: 'Std Dev Upper', value: 'std_deviation_bounds_upper' },
  96. { text: 'Std Dev Lower', value: 'std_deviation_bounds_lower' },
  97. ];
  98. export const intervalOptions = [
  99. { text: 'auto', value: 'auto' },
  100. { text: '10s', value: '10s' },
  101. { text: '1m', value: '1m' },
  102. { text: '5m', value: '5m' },
  103. { text: '10m', value: '10m' },
  104. { text: '20m', value: '20m' },
  105. { text: '1h', value: '1h' },
  106. { text: '1d', value: '1d' },
  107. ];
  108. export const movingAvgModelOptions = [
  109. { text: 'Simple', value: 'simple' },
  110. { text: 'Linear', value: 'linear' },
  111. { text: 'Exponentially Weighted', value: 'ewma' },
  112. { text: 'Holt Linear', value: 'holt' },
  113. { text: 'Holt Winters', value: 'holt_winters' },
  114. ];
  115. export const pipelineOptions = {
  116. moving_avg: [
  117. { text: 'window', default: 5 },
  118. { text: 'model', default: 'simple' },
  119. { text: 'predict', default: undefined },
  120. { text: 'minimize', default: false },
  121. ],
  122. derivative: [{ text: 'unit', default: undefined }],
  123. };
  124. export const movingAvgModelSettings = {
  125. simple: [],
  126. linear: [],
  127. ewma: [{ text: 'Alpha', value: 'alpha', default: undefined }],
  128. holt: [{ text: 'Alpha', value: 'alpha', default: undefined }, { text: 'Beta', value: 'beta', default: undefined }],
  129. holt_winters: [
  130. { text: 'Alpha', value: 'alpha', default: undefined },
  131. { text: 'Beta', value: 'beta', default: undefined },
  132. { text: 'Gamma', value: 'gamma', default: undefined },
  133. { text: 'Period', value: 'period', default: undefined },
  134. { text: 'Pad', value: 'pad', default: undefined, isCheckbox: true },
  135. ],
  136. };
  137. export function getMetricAggTypes(esVersion) {
  138. return _.filter(metricAggTypes, function(f) {
  139. if (f.minVersion) {
  140. return f.minVersion <= esVersion;
  141. } else {
  142. return true;
  143. }
  144. });
  145. }
  146. export function getPipelineOptions(metric) {
  147. if (!isPipelineAgg(metric.type)) {
  148. return [];
  149. }
  150. return pipelineOptions[metric.type];
  151. }
  152. export function isPipelineAgg(metricType) {
  153. if (metricType) {
  154. var po = pipelineOptions[metricType];
  155. return po !== null && po !== undefined;
  156. }
  157. return false;
  158. }
  159. export function getPipelineAggOptions(targets) {
  160. var result = [];
  161. _.each(targets.metrics, function(metric) {
  162. if (!isPipelineAgg(metric.type)) {
  163. result.push({ text: describeMetric(metric), value: metric.id });
  164. }
  165. });
  166. return result;
  167. }
  168. export function getMovingAvgSettings(model, filtered) {
  169. var filteredResult = [];
  170. if (filtered) {
  171. _.each(movingAvgModelSettings[model], function(setting) {
  172. if (!setting.isCheckbox) {
  173. filteredResult.push(setting);
  174. }
  175. });
  176. return filteredResult;
  177. }
  178. return movingAvgModelSettings[model];
  179. }
  180. export function getOrderByOptions(target) {
  181. var metricRefs = [];
  182. _.each(target.metrics, function(metric) {
  183. if (metric.type !== 'count') {
  184. metricRefs.push({ text: describeMetric(metric), value: metric.id });
  185. }
  186. });
  187. return orderByOptions.concat(metricRefs);
  188. }
  189. export function describeOrder(order) {
  190. var def = _.find(orderOptions, { value: order });
  191. return def.text;
  192. }
  193. export function describeMetric(metric) {
  194. var def = _.find(metricAggTypes, { value: metric.type });
  195. return def.text + ' ' + metric.field;
  196. }
  197. export function describeOrderBy(orderBy, target) {
  198. var def = _.find(orderByOptions, { value: orderBy });
  199. if (def) {
  200. return def.text;
  201. }
  202. var metric = _.find(target.metrics, { id: orderBy });
  203. if (metric) {
  204. return describeMetric(metric);
  205. } else {
  206. return 'metric not found';
  207. }
  208. }