import { reject } from 'lodash' ; import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types' ; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import { fromKueryExpression , toElasticsearchQuery } from '@kbn/es-query' ; function isUndefinedOrNull ( value ) { return value === undefined || value === null ; } export function termQuery < T extends string > ( field , value ) { if ( isUndefinedOrNull ( value ) ) { return [ ] ; } return [ { term : { [ field ] : value } } ] ; } export function termsQuery ( field , ... values ) { const filtered = reject ( values , isUndefinedOrNull ) ; if ( ! filtered . length ) { return [ ] ; } return [ { terms : { [ field ] : filtered } } ] ; } export function rangeQuery ( start ? , end ? , field = '@timestamp' ) { return [ { range : { [ field ] : { gte : start , lte : end , format : 'epoch_millis' , } , } , } , ] ; } export function kqlQuery ( kql ) { if ( ! kql ) { return [ ] ; } const ast = fromKueryExpression ( kql ) ; return [ toElasticsearchQuery ( ast ) ] ; }