import { Filter , Query } from '@kbn/es-query' ; export interface Pre600FilterQuery { query : { query_string ? : { query : string ; } & { [ key ] : unknown ; } ; } ; } export interface SearchSourcePre600 { filter ? : Array < Filter | Pre600FilterQuery > ; } export interface SearchSource730 { filter : Filter [ ] ; query : Query ; highlightAll ? : boolean ; version ? : boolean ; } function isQueryFilter ( filter ) { return filter . query !== undefined && ! ( filter as Filter ) . meta ; } export function moveFiltersToQuery ( searchSource ) { const searchSource730 = { ... searchSource , filter : [ ] , query : ( searchSource as SearchSource730 ) . query || { query : '' , language : 'kuery' , } , } ; if ( ! searchSource . filter ) { searchSource . filter = [ ] ; } searchSource . filter . forEach ( ( filter ) => { if ( isQueryFilter ( filter ) ) { searchSource730 . query = { query : filter . query . query_string ? filter . query . query_string . query : '' , language : 'lucene' , } ; } else { searchSource730 . filter . push ( filter ) ; } } ) ; return searchSource730 ; }