Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function loadAction({
const stats = createStats(name, log);
const files = prioritizeMappings(await readDirectory(inputDir));
const kibanaPluginIds = await kbnClient.plugins.getEnabledIds();
const targetsWithoutIdGeneration: string[] = [];

// a single stream that emits records from all archive files, in
// order, so that createIndexStream can track the state of indexes
Expand Down Expand Up @@ -107,8 +108,16 @@ export async function loadAction({
docsOnly,
isArchiveInExceptionList,
log,
targetsWithoutIdGeneration,
}),
createIndexDocRecordsStream(client, stats, progress, useCreate, performance),
createIndexDocRecordsStream(
client,
stats,
progress,
useCreate,
performance,
targetsWithoutIdGeneration
),
]);

progress.deactivate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { Client } from '@elastic/elasticsearch';
import AggregateError from 'aggregate-error';
import { Writable } from 'stream';
import { v4 as uuidv4 } from 'uuid';
import { Stats } from '../stats';
import { Progress } from '../progress';
import { ES_CLIENT_HEADERS } from '../../client_headers';
Expand All @@ -24,7 +25,8 @@ export function createIndexDocRecordsStream(
stats: Stats,
progress: Progress,
useCreate: boolean = false,
performance?: LoadActionPerfOptions
performance?: LoadActionPerfOptions,
targetsWithoutIdGeneration: string[] = []
) {
async function indexDocs(docs: any[]) {
const operation = useCreate === true ? BulkOperation.Create : BulkOperation.Index;
Expand All @@ -39,10 +41,12 @@ export function createIndexDocRecordsStream(
const body = doc.source;
const op = doc.data_stream ? BulkOperation.Create : operation;
const index = doc.data_stream || doc.index;
// generate id for valid targets if it doesn't exist yet
const id = targetsWithoutIdGeneration.includes(index) ? doc.id : doc.id ?? uuidv4();
ops.set(body, {
[op]: {
_index: index,
_id: doc.id,
_id: id,
},
});
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export function createCreateIndexStream({
docsOnly = false,
isArchiveInExceptionList = false,
log,
targetsWithoutIdGeneration = [],
}: {
client: Client;
stats: Stats;
skipExisting?: boolean;
docsOnly?: boolean;
isArchiveInExceptionList?: boolean;
log: ToolingLog;
targetsWithoutIdGeneration?: string[];
}) {
const skipDocsFromIndices = new Set();

Expand Down Expand Up @@ -110,6 +112,7 @@ export function createCreateIndexStream({
}
);
stats.createdDataStream(dataStream, template.name, { template });
targetsWithoutIdGeneration.push(dataStream);
} catch (err) {
if (err?.meta?.body?.error?.type !== 'resource_already_exists_exception' || attempts >= 3) {
throw err;
Expand Down Expand Up @@ -188,6 +191,9 @@ export function createCreateIndexStream({
}

stats.createdIndex(index, { settings });
if (settings?.index?.mode === 'time_series') {
targetsWithoutIdGeneration.push(index);
}
} catch (err) {
if (
err?.body?.error?.reason?.includes('index exists with the same name as the alias') &&
Expand Down