import * as Either from 'fp-ts/lib/Either' ; import * as TaskEither from 'fp-ts/lib/TaskEither' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { ElasticsearchClient } from '../../../elasticsearch' ; import { IndexMapping } from '../../mappings' ; import { catchRetryableEsClientErrors , RetryableEsClientError , } from './catch_retryable_es_client_errors' ; import { pickupUpdatedMappings } from './pickup_updated_mappings' ; import { DEFAULT_TIMEOUT } from './constants' ; internal export interface UpdateAndPickupMappingsResponse { taskId : string ; } internal export interface UpdateAndPickupMappingsParams { client : ElasticsearchClient ; index : string ; mappings : IndexMapping ; } /**
 * Updates an index's mappings and runs an pickupUpdatedMappings task so that the mapping
 * changes are "picked up". Returns a taskId to track progress.
 */ export const updateAndPickupMappings = ( { client , index , mappings , } ) : TaskEither . TaskEither < RetryableEsClientError , UpdateAndPickupMappingsResponse > => { const putMappingTask = ( ) => { return client . indices . putMapping ( { index , timeout : DEFAULT_TIMEOUT , body : mappings , } ) . then ( ( res ) => { return Either . right ( 'update_mappings_succeeded' as const ) ; } ) . catch ( catchRetryableEsClientErrors ) ; } ; return pipe ( putMappingTask , TaskEither . chain ( ( res ) => { return pickupUpdatedMappings ( client , index ) ; } ) ) ; } ;