import { IBucketAggConfig } from '../bucket_agg_type' ; import { buildPhrasesFilter , buildExistsFilter , buildPhraseFilter , Filter , } from '../../../../../common' ; export const createFilterTerms = ( aggConfig , key , params ) => { const field = aggConfig . params . field ; const indexPattern = aggConfig . aggConfigs . indexPattern ; if ( key === '__other__' ) { const terms = params . terms ; const phraseFilter = buildPhrasesFilter ( field , terms , indexPattern ) ; phraseFilter . meta . negate = true ; const filters = [ phraseFilter ] ; if ( terms . some ( ( term ) => term === '__missing__' ) ) { filters . push ( buildExistsFilter ( field , indexPattern ) ) ; } return filters ; } else if ( key === '__missing__' ) { const existsFilter = buildExistsFilter ( field , indexPattern ) ; existsFilter . meta . negate = true ; return existsFilter ; } return buildPhraseFilter ( field , key , indexPattern ) ; } ;