import { Transform } from 'stream' ; import { Client } from 'elasticsearch' ; import { Stats } from '../stats' ; export function createGenerateIndexRecordsStream ( client , stats ) { return new Transform ( { writableObjectMode : true , readableObjectMode : true , async transform ( indexOrAlias , enc , callback ) { try { const resp = ( await client . indices . get ( { index : indexOrAlias , filterPath : [ '*.settings' , '*.mappings' , '-*.settings.index.creation_date' , '-*.settings.index.uuid' , '-*.settings.index.version' , '-*.settings.index.provided_name' , '-*.settings.index.frozen' , '-*.settings.index.search.throttled' , '-*.settings.index.query' , '-*.settings.index.routing' , ] , } ) ) as Record < string , any > ; for ( const [ index , { settings , mappings } ] of Object . entries ( resp ) ) { const { [ index ] : { aliases } , } = await client . indices . getAlias ( { index } ) ; stats . archivedIndex ( index , { settings , mappings } ) ; this . push ( { type : 'index' , value : { index : index . startsWith ( '.kibana' ) ? '.kibana_1' : index , settings , mappings , aliases , } , } ) ; } callback ( ) ; } catch ( err ) { callback ( err ) ; } } , } ) ; }