import * as Either from 'fp-ts/lib/Either' ; import * as TaskEither from 'fp-ts/lib/TaskEither' ; import * as Option from 'fp-ts/lib/Option' ; import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import { ElasticsearchClient } from '../../../elasticsearch' ; import { catchRetryableEsClientErrors , RetryableEsClientError , } from './catch_retryable_es_client_errors' ; import { BATCH_SIZE } from './constants' ; internal export interface ReindexResponse { taskId : string ; } internal export interface ReindexParams { client : ElasticsearchClient ; sourceIndex : string ; targetIndex : string ; reindexScript : Option . Option < string > ; requireAlias : boolean ; unusedTypesQuery : estypes . QueryDslQueryContainer ; } remarks export const reindex = ( { client , sourceIndex , targetIndex , reindexScript , requireAlias , unusedTypesQuery , } ) : TaskEither . TaskEither < RetryableEsClientError , ReindexResponse > => ( ) => { return client . reindex ( { require_alias : requireAlias , body : { conflicts : 'proceed' , source : { index : sourceIndex , size : BATCH_SIZE , query : unusedTypesQuery , } , dest : { index : targetIndex , op_type : 'create' , } , script : Option . fold < string , undefined | { source : string ; lang : 'painless' ; } > ( ( ) => undefined , ( script ) => ( { source : script , lang : 'painless' , } ) ) ( reindexScript ) , } , refresh : true , wait_for_completion : false , } ) . then ( ( { body : { task : taskId } } ) => { return Either . right ( { taskId : String ( taskId ) } ) ; } ) . catch ( catchRetryableEsClientErrors ) ; } ;