import { buildEsQuery } from '@kbn/es-query' ; import { getTimerange , overwrite } from '../../helpers' ; import type { TableRequestProcessorsFunction } from './types' ; export const query = ( { req , panel , esQueryConfig , seriesIndex , buildSeriesMetaParams } ) => ( next ) => async ( doc ) => { const { timeField } = await buildSeriesMetaParams ( ) ; const { from , to } = getTimerange ( req ) ; const indexPattern = seriesIndex . indexPattern || undefined ; doc . size = 0 ; const queries = ! panel . ignore_global_filter ? req . body . query : [ ] ; const filters = ! panel . ignore_global_filter ? req . body . filters : [ ] ; doc . query = buildEsQuery ( indexPattern , queries , filters , esQueryConfig ) ; const boolFilters = [ ] ; if ( timeField ) { const timerange = { range : { [ timeField ] : { gte : from . toISOString ( ) , lte : to . toISOString ( ) , format : 'strict_date_optional_time' , } , } , } ; boolFilters . push ( timerange ) ; } if ( panel . filter ) { boolFilters . push ( buildEsQuery ( indexPattern , [ panel . filter ] , [ ] , esQueryConfig ) ) ; } overwrite ( doc , 'query.bool.must' , boolFilters ) ; return next ( doc ) ; } ;