import { CoreSetup } from 'src/core/public' ; import type { DataView } from '../../../../../../../../src/plugins/data_views/public' ; import { SavedSearchQuery } from '../../../contexts/ml' ; import { OMIT_FIELDS } from '../../../../../common/constants/field_types' ; import { IndexPatternTitle } from '../../../../../common/types/kibana' ; import { DEFAULT_SAMPLER_SHARD_SIZE } from '../../../../../common/constants/field_histograms' ; import { ml } from '../../../services/ml_api_service' ; import { FieldHistogramRequestConfig } from '../common/request' ; import { RuntimeMappings } from '../../../../../common/types/fields' ; const MAX_EXAMPLES_DEFAULT = 10 ; export class DataLoader { private _indexPattern : DataView ; private _runtimeMappings : RuntimeMappings ; private _indexPatternTitle : IndexPatternTitle = '' ; private _maxExamples : number = MAX_EXAMPLES_DEFAULT ; constructor ( indexPattern , toastNotifications ? ) { this . _indexPattern = indexPattern ; this . _runtimeMappings = this . _indexPattern . getComputedFields ( ) . runtimeFields as RuntimeMappings ; this . _indexPatternTitle = indexPattern . title ; } async loadFieldHistograms ( fields , query , samplerShardSize = DEFAULT_SAMPLER_SHARD_SIZE , editorRuntimeMappings ? ) { const stats = await ml . getVisualizerFieldHistograms ( { indexPattern : this . _indexPatternTitle , query , fields , samplerShardSize , runtimeMappings : editorRuntimeMappings || this . _runtimeMappings , } ) ; return stats ; } public set maxExamples ( max ) { this . _maxExamples = max ; } public get maxExamples ( ) : number { return this . _maxExamples ; } public isDisplayField ( fieldName ) { return ! OMIT_FIELDS . includes ( fieldName ) ; } }