@@ -52,20 +52,36 @@ export class OpendistroClient {
5252
5353 public async getIndexPatternIdByIndexName ( indexName : string ) : Promise < string >
5454 {
55- const url = this . dashboardPrivateUrl + '/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern&search=' + indexName ;
56- const res = await fetch ( url , {
57- headers : this . getAuthHeaders ( )
58- } ) ;
59- if ( ! res . ok ) {
60- const errorBody = await res . text ( ) ;
61- throw new Error ( `HTTP error! Status: ${ res . status } , Body: ${ errorBody } ` ) ;
62- }
63- const json = await res . json ( ) ;
64- if ( json ?. total === 0 ) {
65- throw new Error ( `Index pattern for ${ indexName } not found.` ) ;
55+ const base = indexName . split ( '-' ) ;
56+ if ( base [ base . length - 1 ] === '*' ) {
57+ base . pop ( )
6658 }
59+ while ( true ) {
60+ const indexNameIteration = base . join ( '-' ) + '-*' ;
6761
68- return json . saved_objects [ 0 ] . id ;
62+ const url = this . dashboardPrivateUrl + '/api/saved_objects/_find?fields=title&per_page=10000&type=index-pattern&search=' + indexNameIteration ;
63+ const res = await fetch ( url , {
64+ headers : this . getAuthHeaders ( )
65+ } ) ;
66+ if ( ! res . ok ) {
67+ const errorBody = await res . text ( ) ;
68+ throw new Error ( `HTTP error! Status: ${ res . status } , Body: ${ errorBody } ` ) ;
69+ }
70+ const json = await res . json ( ) ;
71+ if ( json ?. total !== 0 ) {
72+ for ( const indexPattern of json . saved_objects ) {
73+ if ( indexPattern . attributes . title === indexNameIteration ) {
74+ return indexPattern . id ;
75+ }
76+ }
77+ }
78+
79+ base . pop ( ) ;
80+ if ( base . length === 0 ) {
81+ break ;
82+ }
83+ }
84+ throw new Error ( `Index pattern for ${ indexName } not found.` ) ;
6985 }
7086
7187 private getAuthHeaders ( ) : HeadersInit
0 commit comments