Skip to content
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

[BUG] fix median.ts to work for scripted field #1302

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/median.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,41 @@ describe('AggTypeMetricMedianProvider class', () => {
})
).toEqual(10);
});

it('supports scripted fields', () => {
const typesRegistry = mockAggTypesRegistry();
const field = {
name: 'bytes',
scripted: true,
language: 'painless',
script: 'return 456',
};
const indexPattern = {
id: '1234',
title: 'logstash-*',
fields: {
getByName: () => field,
filter: () => [field],
},
} as any;

aggConfigs = new AggConfigs(
indexPattern,
[
{
id: METRIC_TYPES.MEDIAN,
type: METRIC_TYPES.MEDIAN,
schema: 'metric',
params: {
field: 'bytes',
},
},
],
{
typesRegistry,
}
);

expect(aggConfigs.toDsl()).toMatchSnapshot();
});
});
8 changes: 4 additions & 4 deletions src/plugins/data/common/search/aggs/metrics/median.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const getMedianMetricAgg = () => {
name: 'field',
type: 'field',
filterFieldTypes: [OSD_FIELD_TYPES.NUMBER, OSD_FIELD_TYPES.DATE, OSD_FIELD_TYPES.HISTOGRAM],
write(agg, output) {
output.params.field = agg.getParam('field').name;
ananzh marked this conversation as resolved.
Show resolved Hide resolved
output.params.percents = [50];
},
},
{
name: 'percents',
default: [50],
},
],
getValue(agg, bucket) {
Expand Down