import { fromKueryExpression , toOpenSearchQuery , nodeTypes , KueryNode } from '../kuery' ; import { IIndexPattern } from '../../index_patterns' ; import { Query } from '../../query/types' ; export function buildQueryFromKuery ( indexPattern , queries = [ ] , allowLeadingWildcards = false , dateFormatTZ ? ) { const queryASTs = queries . map ( ( query ) => { return fromKueryExpression ( query . query , { allowLeadingWildcards } ) ; } ) ; return buildQuery ( indexPattern , queryASTs , { dateFormatTZ } ) ; } function buildQuery ( indexPattern , queryASTs , config = { } ) { const compoundQueryAST = nodeTypes . function . buildNode ( 'and' , queryASTs ) ; const kueryQuery = toOpenSearchQuery ( compoundQueryAST , indexPattern , config ) ; return Object . assign ( { must : [ ] , filter : [ ] , should : [ ] , must_not : [ ] , } , kueryQuery . bool ) ; }