-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Timelion] Fixes bug with escape colons in field names in the metric/split parameter #96770
Changes from 5 commits
8e49305
fd0eac0
07377d1
8a4a472
16b1b51
f447ded
1d1ba2f
bf68a07
671bfae
78b5eea
53bdf8d
dd44a37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { buildAggBody } from './agg_body'; | ||
import { search } from '../../../../../../plugins/data/server'; | ||
const { dateHistogramInterval } = search.aggs; | ||
|
@@ -29,29 +28,37 @@ export default function createDateAgg(config, tlConfig, scriptedFields) { | |
}; | ||
|
||
dateAgg.time_buckets.aggs = {}; | ||
_.each(config.metric, function (metric) { | ||
metric = metric.split(':'); | ||
if (metric[0] === 'count') { | ||
(config.metric || []).forEach((metric) => { | ||
const metricBody = {}; | ||
const [metricName, metricArgs] = metric.split(/:(.+)/); | ||
if (metricName === 'count') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that this is how it was before but do you want to use instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
// 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 | ||
dateAgg.time_buckets.aggs[metric] = { | ||
metricBody[metricName] = { | ||
bucket_script: { | ||
buckets_path: '_count', | ||
script: { source: '_value', lang: 'expression' }, | ||
}, | ||
}; | ||
} else if (metric[0] && metric[1]) { | ||
const metricName = metric[0] + '(' + metric[1] + ')'; | ||
dateAgg.time_buckets.aggs[metricName] = {}; | ||
dateAgg.time_buckets.aggs[metricName][metric[0]] = buildAggBody(metric[1], scriptedFields); | ||
if (metric[0] === 'percentiles' && metric[2]) { | ||
let percentList = metric[2].split(','); | ||
} else if (metricName && metricArgs) { | ||
const [field, percentArgs] = metricArgs.split(/:(\d.*)/); | ||
const metricKey = metricName + '(' + field + ')'; | ||
|
||
metricBody[metricKey] = { [metricName]: buildAggBody(field, scriptedFields) }; | ||
|
||
if (metricName === 'percentiles' && percentArgs) { | ||
let percentList = percentArgs.split(','); | ||
percentList = percentList.map((x) => parseFloat(x)); | ||
dateAgg.time_buckets.aggs[metricName][metric[0]].percents = percentList; | ||
metricBody[metricKey][metricName].percents = percentList; | ||
} | ||
} else { | ||
throw new Error('`metric` requires metric:field or simply count'); | ||
} | ||
|
||
dateAgg.time_buckets.aggs = { | ||
...dateAgg.time_buckets.aggs, | ||
...metricBody, | ||
}; | ||
}); | ||
|
||
return dateAgg; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ❤️