import { get } from 'lodash' ; import * as literal from '../node_types/literal' ; import { IIndexPattern , KueryNode , IFieldType } from '../../..' ; export function buildNodeParams ( fieldName ) { return { arguments : [ literal . buildNode ( fieldName ) ] , } ; } export function toOpenSearchQuery ( node , indexPattern ? , config = { } , context = { } ) { const { arguments : [ fieldNameArg ] , } = node ; const fullFieldNameArg = { ... fieldNameArg , value : context ?. nested ? `${ context . nested . path }.${ fieldNameArg . value }` : fieldNameArg . value , } ; const fieldName = literal . toOpenSearchQuery ( fullFieldNameArg ) ; const field = get ( indexPattern , 'fields' , [ ] ) . find ( ( fld ) => fld . name === fieldName ) ; if ( field && ( field as IFieldType ) . scripted ) { throw new Error ( `Exists query does not support scripted fields` ) ; } return { exists : { field : fieldName } , } ; }