Skip to content

Commit 288ae1b

Browse files
[ML] File upload: include existing doc count when checking for ingested doc count (elastic#234333)
When checking to see of all ingested docs are now searchable, it should take into account existing docs as we could be uploading to an existing index.
1 parent 99c57c2 commit 288ae1b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

x-pack/platform/packages/shared/file-upload/file_upload_manager/doc_count_service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class DocCountService {
1515
private indexName: string | null = null;
1616
private indexSearchableSubscription: Subscription | null = null;
1717
private allDocsSearchableSubscription: Subscription | null = null;
18+
private initialDocCount: number = 0;
1819

1920
constructor(
2021
private fileUpload: FileUploadStartApi,
@@ -44,10 +45,11 @@ export class DocCountService {
4445
}
4546

4647
public startAllDocsSearchableCheck(indexName: string, totalDocCount: number): void {
48+
const expectedDocCount = totalDocCount + this.initialDocCount;
4749
this.indexName = indexName;
4850
this.allDocsSearchableSubscription = timer(0, POLL_INTERVAL * 1000)
4951
.pipe(
50-
exhaustMap(() => this.isSearchable$(totalDocCount)),
52+
exhaustMap(() => this.isSearchable$(expectedDocCount)),
5153
takeWhile((isSearchable) => !isSearchable, true) // takeUntil we get `true`, including the final one
5254
)
5355
.pipe(finalize(() => this.onAllDocsSearchable(indexName)))
@@ -65,4 +67,13 @@ export class DocCountService {
6567
catchError((err) => throwError(() => err))
6668
);
6769
}
70+
71+
public async loadInitialIndexCount(indexName: string) {
72+
const { count } = await this.fileUpload.isIndexSearchable(indexName, 0);
73+
this.initialDocCount = count;
74+
}
75+
76+
public resetInitialDocCount() {
77+
this.initialDocCount = 0;
78+
}
6879
}

x-pack/platform/packages/shared/file-upload/file_upload_manager/file_manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,19 @@ export class FileUploadManager {
483483
let pipelinesCreated = false;
484484
let initializeImportResp: InitializeImportResponse | undefined;
485485

486+
this.docCountService.resetInitialDocCount();
487+
const isExistingIndex = this.isExistingIndexUpload();
488+
if (isExistingIndex) {
489+
await this.docCountService.loadInitialIndexCount(indexName);
490+
}
491+
486492
try {
487493
initializeImportResp = await this.importer.initializeImport(
488494
indexName,
489495
this.getSettings().json,
490496
mappings,
491497
pipelines,
492-
this.isExistingIndexUpload()
498+
isExistingIndex
493499
);
494500

495501
this.docCountService.startIndexSearchableCheck(indexName);

x-pack/platform/plugins/private/file_upload/public/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface GetTimeFieldRangeResponse {
4747

4848
export interface IsIndexSearchableResponse {
4949
isSearchable: boolean;
50+
count: number;
5051
}
5152

5253
export const FileUploadComponent = GeoUploadWizardAsyncWrapper;

x-pack/platform/plugins/private/file_upload/server/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
592592
const isSearchable = count >= expectedCount;
593593

594594
return response.ok({
595-
body: { isSearchable },
595+
body: { isSearchable, count },
596596
});
597597
} catch (e) {
598598
return response.customError(wrapError(e));

0 commit comments

Comments
 (0)