import { difference } from 'lodash' ; import { IndexPattern , IndexPatternField } from 'src/plugins/data/public' ; export function getIndexPatternFieldList ( indexPattern ? , fieldCounts ? ) { if ( ! indexPattern || ! fieldCounts ) return [ ] ; const fieldNamesInDocs = Object . keys ( fieldCounts ) ; const fieldNamesInIndexPattern = indexPattern . fields . getAll ( ) . map ( ( fld ) => fld . name ) ; const unknownTypes = [ ] ; difference ( fieldNamesInDocs , fieldNamesInIndexPattern ) . forEach ( ( unknownFieldName ) => { unknownTypes . push ( { displayName : String ( unknownFieldName ) , name : String ( unknownFieldName ) , type : 'unknown' , } as IndexPatternField ) ; } ) ; return [ ... indexPattern . fields . getAll ( ) , ... unknownTypes ] ; }