diff --git a/src/es_archiver/lib/indices/create_index_stream.ts b/src/es_archiver/lib/indices/create_index_stream.ts index df9d3bb623ad6..5629f95c7c9c6 100644 --- a/src/es_archiver/lib/indices/create_index_stream.ts +++ b/src/es_archiver/lib/indices/create_index_stream.ts @@ -18,6 +18,8 @@ */ import { Transform, Readable } from 'stream'; +import { inspect } from 'util'; + import { get, once } from 'lodash'; import { Client } from 'elasticsearch'; import { ToolingLog } from '@kbn/dev-utils'; @@ -84,6 +86,18 @@ export function createCreateIndexStream({ stats.createdIndex(index, { settings }); } catch (err) { + if ( + err?.body?.error?.reason?.includes('index exists with the same name as the alias') && + attemptNumber < 3 + ) { + const aliasStr = inspect(aliases); + log.info( + `failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again` + ); + await attemptToCreate(attemptNumber + 1); + return; + } + if ( get(err, 'body.error.type') !== 'resource_already_exists_exception' || attemptNumber >= 3