import { uxLocalUIFilterNames , uxLocalUIFilters , } from '../../../../common/ux_ui_filter' ; import { ESFilter } from '../../../../../../../src/core/types/elasticsearch' ; import { UxUIFilters } from '../../../../typings/ui_filters' ; import { environmentQuery } from '../../../../common/utils/environment_query' ; import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values' ; export function getEsFilter ( uiFilters , exclude ? ) { const localFilterValues = uiFilters ; const mappedFilters = uxLocalUIFilterNames . filter ( ( name ) => { const validFilter = name in localFilterValues ; if ( exclude ) { return name . includes ( 'Excluded' ) && validFilter ; } return ! name . includes ( 'Excluded' ) && validFilter ; } ) . map ( ( filterName ) => { const field = uxLocalUIFilters [ filterName ] ; const value = localFilterValues [ filterName ] ; return { terms : { [ field . fieldName ] : value , } , } ; } ) as ESFilter [ ] ; return [ ... mappedFilters , ... ( exclude ? [ ] : environmentQuery ( uiFilters . environment || ENVIRONMENT_ALL . value ) ) , ] ; }