import { IRouter } from 'kibana/server' ; import { schema } from '@kbn/config-schema' ; import { LicenseState , verifyApiAccess } from '../lib/license_state' ; import { UI_SETTINGS } from '../../../../../src/plugins/data/server' ; export function registerSearchRoute ( { router , licenseState , } ) { router . post ( { path : '/api/graph/searchProxy' , validate : { body : schema . object ( { index : schema . string ( ) , body : schema . object ( { } , { unknowns : 'allow' } ) , } ) , } , } , router . handleLegacyErrors ( async ( { core : { uiSettings : { client : uiSettings } , elasticsearch : { client : esClient } , } , } , request , response ) => { verifyApiAccess ( licenseState ) ; licenseState . notifyUsage ( 'Graph' ) ; const includeFrozen = await uiSettings . get < boolean > ( UI_SETTINGS . SEARCH_INCLUDE_FROZEN ) ; try { return response . ok ( { body : { resp : ( await esClient . asCurrentUser . search ( { index : request . body . index , body : request . body . body , track_total_hits : true , ... ( includeFrozen ? { ignore_throttled : false } : { } ) , } ) ) . body , } , } ) ; } catch ( error ) { return response . customError ( { statusCode : error . statusCode || 500 , body : { message : error . message , } , } ) ; } } ) ) ; }