@@ -14,8 +14,6 @@ import {
14
14
IndexFieldsStrategyRequest ,
15
15
} from '../../../common/search_strategy/index_fields' ;
16
16
17
- import { fieldsBeat } from '../../utils/beat_schema/fields' ;
18
-
19
17
export const securitySolutionIndexFieldsProvider = ( ) : ISearchStrategy <
20
18
IndexFieldsStrategyRequest ,
21
19
IndexFieldsStrategyResponse
@@ -115,11 +113,13 @@ const missingFields: FieldDescriptor[] = [
115
113
* @param index The index its self
116
114
* @param indexesAliasIdx The index within the alias
117
115
*/
118
- export const createFieldItem = (
116
+ export const createFieldItem = async (
119
117
indexesAlias : string [ ] ,
120
118
index : FieldDescriptor ,
121
119
indexesAliasIdx : number
122
- ) : IndexField => {
120
+ ) : Promise < IndexField > => {
121
+ const { fieldsBeat } = await import ( '../../utils/beat_schema/fields' ) ;
122
+
123
123
const alias = indexesAlias [ indexesAliasIdx ] ;
124
124
const splitIndexName = index . name . split ( '.' ) ;
125
125
const indexName =
@@ -154,26 +154,18 @@ export const formatFirstFields = async (
154
154
responsesIndexFields : FieldDescriptor [ ] [ ] ,
155
155
indexesAlias : string [ ]
156
156
) : Promise < IndexField [ ] > => {
157
- return new Promise ( ( resolve ) => {
158
- setTimeout ( ( ) => {
159
- resolve (
160
- responsesIndexFields . reduce (
161
- ( accumulator : IndexField [ ] , indexFields : FieldDescriptor [ ] , indexesAliasIdx : number ) => {
162
- missingFields . forEach ( ( index ) => {
163
- const item = createFieldItem ( indexesAlias , index , indexesAliasIdx ) ;
164
- accumulator . push ( item ) ;
165
- } ) ;
166
- indexFields . forEach ( ( index ) => {
167
- const item = createFieldItem ( indexesAlias , index , indexesAliasIdx ) ;
168
- accumulator . push ( item ) ;
169
- } ) ;
170
- return accumulator ;
171
- } ,
172
- [ ]
173
- )
174
- ) ;
175
- } ) ;
176
- } ) ;
157
+ const result : IndexField [ ] = [ ] ;
158
+
159
+ for ( const [ indexesAliasIdx , indexFields ] of responsesIndexFields . entries ( ) ) {
160
+ for ( const index of missingFields ) {
161
+ result . push ( await createFieldItem ( indexesAlias , index , indexesAliasIdx ) ) ;
162
+ }
163
+ for ( const index of indexFields ) {
164
+ result . push ( await createFieldItem ( indexesAlias , index , indexesAliasIdx ) ) ;
165
+ }
166
+ }
167
+
168
+ return result ;
177
169
} ;
178
170
179
171
/**
0 commit comments