import { uniq , defaultsDeep , cloneDeep } from 'lodash' ; import { PROCESSOR_EVENT } from '../../../../../common/elasticsearch_fieldnames' ; import { ProcessorEvent } from '../../../../../common/processor_event' ; import { ESSearchRequest , ESFilter , } from '../../../../../../../../src/core/types/elasticsearch' ; import { APMEventESSearchRequest , APMEventESTermsEnumRequest } from '.' ; import { ApmIndicesConfig } from '../../../../routes/settings/apm_indices/get_apm_indices' ; const processorEventIndexMap = { [ ProcessorEvent . transaction ] : 'transaction' , [ ProcessorEvent . span ] : 'span' , [ ProcessorEvent . metric ] : 'metric' , [ ProcessorEvent . error ] : 'error' , [ ProcessorEvent . profile ] : 'transaction' , } as const ; export function unpackProcessorEvents ( request , indices ) { const { apm , ... params } = request ; const events = uniq ( apm . events ) ; const index = events . map ( ( event ) => indices [ processorEventIndexMap [ event ] ] ) ; const withFilterForProcessorEvent = defaultsDeep ( cloneDeep ( params ) , { body : { query : { bool : { filter : [ ] , } , } , } , } ) ; withFilterForProcessorEvent . body . query . bool . filter . push ( { terms : { [ PROCESSOR_EVENT ] : events , } , } ) ; return { index , ... withFilterForProcessorEvent , } ; }