import { SERVICE_NAME , TRANSACTION_TYPE , } from '../../../common/elasticsearch_fieldnames' ; import { rangeQuery } from '../../../../observability/server' ; import { Setup } from '../../lib/helpers/setup_request' ; import { getDocumentTypeFilterForTransactions , getProcessorEventForTransactions , } from '../../lib/helpers/transactions' ; export async function getServiceTransactionTypes ( { setup , serviceName , searchAggregatedTransactions , start , end , } ) { const { apmEventClient } = setup ; const params = { apm : { events : [ getProcessorEventForTransactions ( searchAggregatedTransactions ) ] , } , body : { size : 0 , query : { bool : { filter : [ ... getDocumentTypeFilterForTransactions ( searchAggregatedTransactions ) , { term : { [ SERVICE_NAME ] : serviceName } } , ... rangeQuery ( start , end ) , ] , } , } , aggs : { types : { terms : { field : TRANSACTION_TYPE , size : 100 } , } , } , } , } ; const { aggregations } = await apmEventClient . search ( 'get_service_transaction_types' , params ) ; const transactionTypes = aggregations ?. types . buckets . map ( ( bucket ) => bucket . key as string ) || [ ] ; return { transactionTypes } ; }