import { IndexPattern } from '../../../../../../../../src/plugins/data/common' ; import { getField } from '../../../../../common/elasticsearch_util' ; export interface ScriptField { source : string ; lang : string ; } export function getDocValueAndSourceFields ( indexPattern , fieldNames , dateFormat ) { const docValueFields = [ ] ; const sourceOnlyFields = [ ] ; const scriptFields = { } ; fieldNames . forEach ( ( fieldName ) => { const field = getField ( indexPattern , fieldName ) ; if ( field . scripted ) { scriptFields [ field . name ] = { script : { source : field . script || '' , lang : field . lang || '' , } , } ; } else if ( field . readFromDocValues || field . runtimeField ) { const docValueField = field . type === 'date' ? { field : fieldName , format : dateFormat , } : fieldName ; docValueFields . push ( docValueField ) ; } else { sourceOnlyFields . push ( fieldName ) ; } } ) ; return { docValueFields , sourceOnlyFields , scriptFields } ; }