Skip to content

Commit

Permalink
[Timelion] use metric types common constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaanj committed Apr 16, 2021
1 parent 1d1ba2f commit bf68a07
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { buildAggBody } from './agg_body';
import { search } from '../../../../../../plugins/data/server';
import { METRIC_TYPES } from '../../../../../data/common/search/aggs/metrics/index';
const { dateHistogramInterval } = search.aggs;

export default function createDateAgg(config, tlConfig, scriptedFields) {
Expand All @@ -31,7 +32,7 @@ export default function createDateAgg(config, tlConfig, scriptedFields) {
(config.metric || []).forEach((metric) => {
const metricBody = {};
const [metricName, metricArgs] = metric.split(/:(.+)/);
if (metricName === 'count') {
if (metricName === METRIC_TYPES.COUNT) {
// This is pretty lame, but its how the "doc_count" metric has to be implemented at the moment
// It simplifies the aggregation tree walking code considerably
metricBody[metricName] = {
Expand All @@ -48,7 +49,7 @@ export default function createDateAgg(config, tlConfig, scriptedFields) {

metricBody[metricKey] = { [metricName]: buildAggBody(field, scriptedFields) };

if (metricName === 'percentiles' && percentArgs) {
if (metricName === METRIC_TYPES.PERCENTILES && percentArgs) {
let percentList = percentArgs.split(',');
percentList = percentList.map((x) => parseFloat(x));
metricBody[metricKey][metricName].percents = percentList;
Expand Down

0 comments on commit bf68a07

Please sign in to comment.