import { PluginStart as DataPluginStart , IOpenSearchSearchRequest } from 'src/plugins/data/server' ; import { schema } from '@osd/config-schema' ; import { IOpenSearchSearchResponse } from 'src/plugins/data/common' ; import { IRouter } from '../../../../src/core/server' ; import { SERVER_SEARCH_ROUTE_PATH } from '../../common' ; export function registerServerSearchRoute ( router , data ) { router . get ( { path : SERVER_SEARCH_ROUTE_PATH , validate : { query : schema . object ( { index : schema . maybe ( schema . string ( ) ) , field : schema . maybe ( schema . string ( ) ) , } ) , } , } , async ( context , request , response ) => { const { index , field } = request . query ; const res = await data . search . search ( context , { params : { index , body : { aggs : { '1' : { avg : { field , } , } , } , } , waitForCompletionTimeout : '5m' , keepAlive : '5m' , } , } as IOpenSearchSearchRequest , { } ) ; return response . ok ( { body : { aggs : ( res as IOpenSearchSearchResponse ) . rawResponse . aggregations , } , } ) ; } ) ; }