99import _ from 'lodash' ;
1010
1111import { Framework } from '../plugin' ;
12- import type { TimeseriesVisData } from '../../common/types' ;
12+ import type { TimeseriesVisData , FetchedIndexPattern , Series } from '../../common/types' ;
1313import { PANEL_TYPES } from '../../common/enums' ;
1414import type {
1515 VisTypeTimeseriesVisDataRequest ,
@@ -20,6 +20,8 @@ import { getSeriesData } from './vis_data/get_series_data';
2020import { getTableData } from './vis_data/get_table_data' ;
2121import { getEsQueryConfig } from './vis_data/helpers/get_es_query_uisettings' ;
2222import { getCachedIndexPatternFetcher } from './search_strategies/lib/cached_index_pattern_fetcher' ;
23+ import { MAX_BUCKETS_SETTING } from '../../common/constants' ;
24+ import { getIntervalAndTimefield } from './vis_data/get_interval_and_timefield' ;
2325
2426export async function getVisData (
2527 requestContext : VisTypeTimeseriesRequestHandlerContext ,
@@ -32,15 +34,41 @@ export async function getVisData(
3234 const esQueryConfig = await getEsQueryConfig ( uiSettings ) ;
3335
3436 const promises = request . body . panels . map ( ( panel ) => {
37+ const cachedIndexPatternFetcher = getCachedIndexPatternFetcher ( indexPatternsService , {
38+ fetchKibanaIndexForStringIndexes : Boolean ( panel . use_kibana_indexes ) ,
39+ } ) ;
3540 const services : VisTypeTimeseriesRequestServices = {
3641 esQueryConfig,
3742 esShardTimeout,
3843 indexPatternsService,
3944 uiSettings,
45+ cachedIndexPatternFetcher,
4046 searchStrategyRegistry : framework . searchStrategyRegistry ,
41- cachedIndexPatternFetcher : getCachedIndexPatternFetcher ( indexPatternsService , {
42- fetchKibanaIndexForStringIndexes : Boolean ( panel . use_kibana_indexes ) ,
43- } ) ,
47+ buildSeriesMetaParams : async (
48+ index : FetchedIndexPattern ,
49+ useKibanaIndexes : boolean ,
50+ series ?: Series
51+ ) => {
52+ /** This part of code is required to try to get the default timefield for string indices.
53+ * The rest of the functionality available for Kibana indexes should not be active **/
54+ if ( ! useKibanaIndexes && index . indexPatternString ) {
55+ index = await cachedIndexPatternFetcher ( index . indexPatternString , true ) ;
56+ }
57+
58+ const maxBuckets = await uiSettings . get < number > ( MAX_BUCKETS_SETTING ) ;
59+ const { min, max } = request . body . timerange ;
60+
61+ return getIntervalAndTimefield (
62+ panel ,
63+ index ,
64+ {
65+ min,
66+ max,
67+ maxBuckets,
68+ } ,
69+ series
70+ ) ;
71+ } ,
4472 } ;
4573
4674 return panel . type === PANEL_TYPES . TABLE
0 commit comments