import { IScopedClusterClient } from 'kibana/server' ; import { wrapError } from '../client/error_wrapper' ; import { DataVisualizer } from '../models/data_visualizer' ; import { HistogramField } from '../models/data_visualizer/data_visualizer' ; import { dataVisualizerFieldHistogramsSchema , indexPatternSchema , } from './schemas/data_visualizer_schema' ; import { RouteInitialization } from '../types' ; import { RuntimeMappings } from '../../common/types/fields' ; function getHistogramsForFields ( client , indexPattern , query , fields , samplerShardSize , runtimeMappings ) { const dv = new DataVisualizer ( client ) ; return dv . getHistogramsForFields ( indexPattern , query , fields , samplerShardSize , runtimeMappings ) ; } /**
 * Routes for the index data visualizer.
 */ export function dataVisualizerRoutes ( { router , routeGuard } ) { apiGroup api apiName apiDescription apiSchema apiSchema apiSuccess router . post ( { path : '/api/ml/data_visualizer/get_field_histograms/{indexPattern}' , validate : { params : indexPatternSchema , body : dataVisualizerFieldHistogramsSchema , } , options : { tags : [ 'access:ml:canAccessML' ] , } , } , routeGuard . basicLicenseAPIGuard ( async ( { client , request , response } ) => { try { const { params : { indexPattern } , body : { query , fields , samplerShardSize , runtimeMappings } , } = request ; const results = await getHistogramsForFields ( client , indexPattern , query , fields , samplerShardSize , runtimeMappings ) ; return response . ok ( { body : results , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; }