import { i18n } from '@osd/i18n' ; import { MetricAggType } from './metric_agg_type' ; import { METRIC_TYPES } from './metric_agg_types' ; import { OSD_FIELD_TYPES } from '../../../../common' ; import { BaseAggParams } from '../types' ; const medianTitle = i18n . translate ( 'data.search.aggs.metrics.medianTitle' , { defaultMessage : 'Median' , } ) ; export interface AggParamsMedian extends BaseAggParams { field : string ; } export const getMedianMetricAgg = ( ) => { return new MetricAggType ( { name : METRIC_TYPES . MEDIAN , dslName : 'percentiles' , title : medianTitle , makeLabel ( aggConfig ) { return i18n . translate ( 'data.search.aggs.metrics.medianLabel' , { defaultMessage : 'Median {field}' , values : { field : aggConfig . getFieldDisplayName ( ) } , } ) ; } , params : [ { 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 ; output . params . percents = [ 50 ] ; } , } , ] , getValue ( agg , bucket ) { return bucket [ agg . id ] . values [ '50.0' ] ; } , } ) ; } ;