import { ESFilter } from 'src/core/types/elasticsearch' ; import { SERVICE_ENVIRONMENT } from '../../../../../common/elasticsearch_fieldnames' ; import { ENVIRONMENT_ALL , ENVIRONMENT_NOT_DEFINED , } from '../../../../../common/environment_filter_values' ; type QueryDslQueryContainer = ESFilter ; export function environmentQuery ( environment ) { if ( ! environment || environment === ENVIRONMENT_ALL . value ) { return [ ] ; } if ( environment === ENVIRONMENT_NOT_DEFINED . value ) { return [ { bool : { must_not : { exists : { field : SERVICE_ENVIRONMENT } } } } ] ; } return [ { term : { [ SERVICE_ENVIRONMENT ] : environment } } ] ; }