import { ESFilter } from '../../../../../../../src/core/types/elasticsearch' ; import { ERROR_GROUP_ID , PROCESSOR_EVENT , SERVICE_NAME , TRANSACTION_NAME , TRANSACTION_TYPE , } from '../../../../common/elasticsearch_fieldnames' ; import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values' ; import { UIProcessorEvent } from '../../../../common/processor_event' ; import { environmentQuery } from '../../../../common/utils/environment_query' ; import { ApmUrlParams } from '../../../context/url_params_context/types' ; export function getBoolFilter ( { groupId , processorEvent , serviceName , environment , urlParams , } ) { const boolFilter = [ ] ; if ( serviceName ) { boolFilter . push ( { term : { [ SERVICE_NAME ] : serviceName } , } ) ; } boolFilter . push ( ... environmentQuery ( environment ?? ENVIRONMENT_ALL . value ) ) ; if ( urlParams . transactionType ) { boolFilter . push ( { term : { [ TRANSACTION_TYPE ] : urlParams . transactionType } , } ) ; } switch ( processorEvent ) { case 'transaction' : boolFilter . push ( { term : { [ PROCESSOR_EVENT ] : 'transaction' } , } ) ; if ( urlParams . transactionName ) { boolFilter . push ( { term : { [ TRANSACTION_NAME ] : urlParams . transactionName } , } ) ; } if ( urlParams . transactionType ) { boolFilter . push ( { term : { [ TRANSACTION_TYPE ] : urlParams . transactionType } , } ) ; } break ; case 'error' : boolFilter . push ( { term : { [ PROCESSOR_EVENT ] : 'error' } , } ) ; if ( groupId ) { boolFilter . push ( { term : { [ ERROR_GROUP_ID ] : groupId } , } ) ; } break ; case 'metric' : boolFilter . push ( { term : { [ PROCESSOR_EVENT ] : 'metric' } , } ) ; break ; default : boolFilter . push ( { bool : { should : [ { term : { [ PROCESSOR_EVENT ] : 'error' } } , { term : { [ PROCESSOR_EVENT ] : 'transaction' } } , { term : { [ PROCESSOR_EVENT ] : 'metric' } } , ] , } , } ) ; } return boolFilter ; }