import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types' ; import { cloneDeep } from 'lodash' ; import { isPopulatedObject } from './object_utils' ; export const addExcludeFrozenToQuery = ( originalQuery ) => { const FROZEN_TIER_TERM = { term : { _tier : { value : 'data_frozen' , } , } , } ; if ( ! originalQuery ) { return { bool : { must_not : [ FROZEN_TIER_TERM ] , } , } ; } const query = cloneDeep ( originalQuery ) ; delete query . match_all ; if ( isPopulatedObject ( query . bool ) ) { if ( Array . isArray ( query . bool . must_not ) ) { query . bool . must_not . push ( FROZEN_TIER_TERM ) ; } else { if ( isPopulatedObject ( query . bool . must_not ) ) { query . bool . must_not = [ query . bool . must_not , FROZEN_TIER_TERM ] ; } if ( query . bool . must_not === undefined ) { query . bool . must_not = [ FROZEN_TIER_TERM ] ; } } } else { query . bool = { must_not : [ FROZEN_TIER_TERM ] , } ; } return query ; } ;