Skip to content

Commit 4951e29

Browse files
Removed unused method searchForOutdatedDocuments (#157470)
This method is no longer used (replaced by `readWithPit`). --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 76f6fd9 commit 4951e29

6 files changed

Lines changed: 38 additions & 234 deletions

File tree

packages/core/saved-objects/core-saved-objects-migration-server-internal/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export {
3232
updateAliases,
3333
transformDocs,
3434
setWriteBlock,
35-
searchForOutdatedDocuments,
3635
removeWriteBlock,
3736
reindex,
3837
readWithPit,
@@ -45,7 +44,6 @@ export {
4544
export type {
4645
OpenPitResponse,
4746
ReadWithPit,
48-
SearchResponse,
4947
ReindexResponse,
5048
UpdateByQueryResponse,
5149
UpdateAndPickupMappingsResponse,

packages/core/saved-objects/core-saved-objects-migration-server-internal/src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ We can’t use the temporary index as our target index because one instance can
426426

427427
## OUTDATED_DOCUMENTS_SEARCH
428428
### Next action
429-
`searchForOutdatedDocuments`
429+
`readWithPit(outdatedDocumentsQuery)`
430430

431431
Search for outdated saved object documents. Will return one batch of
432432
documents.

packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ export { checkForUnknownDocs } from './check_for_unknown_docs';
118118

119119
export { waitForPickupUpdatedMappingsTask } from './wait_for_pickup_updated_mappings_task';
120120

121-
export type {
122-
SearchResponse,
123-
SearchForOutdatedDocumentsOptions,
124-
} from './search_for_outdated_documents';
125-
export { searchForOutdatedDocuments } from './search_for_outdated_documents';
126-
127121
export type { BulkOverwriteTransformedDocumentsParams } from './bulk_overwrite_transformed_documents';
128122
export { bulkOverwriteTransformedDocuments } from './bulk_overwrite_transformed_documents';
129123

packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/search_for_outdated_documents.test.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/search_for_outdated_documents.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/core/server/integration_tests/saved_objects/migrations/group3/actions/actions.test.ts

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import {
2323
reindex,
2424
readWithPit,
2525
type ReadWithPit,
26-
searchForOutdatedDocuments,
27-
type SearchResponse,
2826
setWriteBlock,
2927
updateAliases,
3028
waitForReindexTask,
@@ -724,14 +722,9 @@ describe('migration actions', () => {
724722
}
725723
`);
726724

727-
const results = (
728-
(await searchForOutdatedDocuments(client, {
729-
batchSize: 1000,
730-
targetIndex: 'reindex_target',
731-
outdatedDocumentsQuery: undefined,
732-
})()) as Either.Right<SearchResponse>
733-
).right.outdatedDocuments;
734-
expect(results.map((doc) => doc._source.title).sort()).toMatchInlineSnapshot(`
725+
const results = await client.search({ index: 'reindex_target', size: 1000 });
726+
expect((results.hits?.hits as SavedObjectsRawDoc[]).map((doc) => doc._source.title).sort())
727+
.toMatchInlineSnapshot(`
735728
Array [
736729
"doc 1",
737730
"doc 2",
@@ -764,14 +757,9 @@ describe('migration actions', () => {
764757
}
765758
`);
766759

767-
const results = (
768-
(await searchForOutdatedDocuments(client, {
769-
batchSize: 1000,
770-
targetIndex: 'reindex_target_excluded_docs',
771-
outdatedDocumentsQuery: undefined,
772-
})()) as Either.Right<SearchResponse>
773-
).right.outdatedDocuments;
774-
expect(results.map((doc) => doc._source.title).sort()).toMatchInlineSnapshot(`
760+
const results = await client.search({ index: 'reindex_target_excluded_docs', size: 1000 });
761+
expect((results.hits?.hits as SavedObjectsRawDoc[]).map((doc) => doc._source.title).sort())
762+
.toMatchInlineSnapshot(`
775763
Array [
776764
"doc 1",
777765
"doc 2",
@@ -796,14 +784,10 @@ describe('migration actions', () => {
796784
"right": "reindex_succeeded",
797785
}
798786
`);
799-
const results = (
800-
(await searchForOutdatedDocuments(client, {
801-
batchSize: 1000,
802-
targetIndex: 'reindex_target_2',
803-
outdatedDocumentsQuery: undefined,
804-
})()) as Either.Right<SearchResponse>
805-
).right.outdatedDocuments;
806-
expect(results.map((doc) => doc._source.title).sort()).toMatchInlineSnapshot(`
787+
788+
const results = await client.search({ index: 'reindex_target_2', size: 1000 });
789+
expect((results.hits?.hits as SavedObjectsRawDoc[]).map((doc) => doc._source.title).sort())
790+
.toMatchInlineSnapshot(`
807791
Array [
808792
"doc 1_updated",
809793
"doc 2_updated",
@@ -850,14 +834,9 @@ describe('migration actions', () => {
850834
`);
851835

852836
// Assert that documents weren't overridden by the second, unscripted reindex
853-
const results = (
854-
(await searchForOutdatedDocuments(client, {
855-
batchSize: 1000,
856-
targetIndex: 'reindex_target_3',
857-
outdatedDocumentsQuery: undefined,
858-
})()) as Either.Right<SearchResponse>
859-
).right.outdatedDocuments;
860-
expect(results.map((doc) => doc._source.title).sort()).toMatchInlineSnapshot(`
837+
const results = await client.search({ index: 'reindex_target_3', size: 1000 });
838+
expect((results.hits?.hits as SavedObjectsRawDoc[]).map((doc) => doc._source.title).sort())
839+
.toMatchInlineSnapshot(`
861840
Array [
862841
"doc 1_updated",
863842
"doc 2_updated",
@@ -872,13 +851,8 @@ describe('migration actions', () => {
872851
// Simulate a reindex that only adds some of the documents from the
873852
// source index into the target index
874853
await createIndex({ client, indexName: 'reindex_target_4', mappings: { properties: {} } })();
875-
const sourceDocs = (
876-
(await searchForOutdatedDocuments(client, {
877-
batchSize: 1000,
878-
targetIndex: 'existing_index_with_docs',
879-
outdatedDocumentsQuery: undefined,
880-
})()) as Either.Right<SearchResponse>
881-
).right.outdatedDocuments
854+
const response = await client.search({ index: 'existing_index_with_docs', size: 1000 });
855+
const sourceDocs = (response.hits?.hits as SavedObjectsRawDoc[])
882856
.slice(0, 2)
883857
.map(({ _id, _source }) => ({
884858
_id,
@@ -909,14 +883,9 @@ describe('migration actions', () => {
909883
`);
910884
// Assert that existing documents weren't overridden, but that missing
911885
// documents were added by the reindex
912-
const results = (
913-
(await searchForOutdatedDocuments(client, {
914-
batchSize: 1000,
915-
targetIndex: 'reindex_target_4',
916-
outdatedDocumentsQuery: undefined,
917-
})()) as Either.Right<SearchResponse>
918-
).right.outdatedDocuments;
919-
expect(results.map((doc) => doc._source.title).sort()).toMatchInlineSnapshot(`
886+
const results = await client.search({ index: 'reindex_target_4', size: 1000 });
887+
expect((results.hits?.hits as SavedObjectsRawDoc[]).map((doc) => doc._source.title).sort())
888+
.toMatchInlineSnapshot(`
920889
Array [
921890
"doc 1",
922891
"doc 2",
@@ -1446,16 +1415,15 @@ describe('migration actions', () => {
14461415
})();
14471416

14481417
// Assert that we can't search over the unmapped fields of the document
1449-
const originalSearchResults = (
1450-
(await searchForOutdatedDocuments(client, {
1451-
batchSize: 1000,
1452-
targetIndex: 'existing_index_without_mappings',
1453-
outdatedDocumentsQuery: {
1454-
match: { title: { query: 'doc' } },
1455-
},
1456-
})()) as Either.Right<SearchResponse>
1457-
).right.outdatedDocuments;
1458-
expect(originalSearchResults.length).toBe(0);
1418+
1419+
const originalSearchResults = await client.search({
1420+
index: 'existing_index_without_mappings',
1421+
size: 1000,
1422+
query: {
1423+
match: { title: { query: 'doc' } },
1424+
},
1425+
});
1426+
expect(originalSearchResults.hits?.hits.length).toBe(0);
14591427

14601428
// Update and pickup mappings so that the title field is searchable
14611429
const res = await updateAndPickupMappings({
@@ -1472,16 +1440,14 @@ describe('migration actions', () => {
14721440
await waitForPickupUpdatedMappingsTask({ client, taskId, timeout: '60s' })();
14731441

14741442
// Repeat the search expecting to be able to find the existing documents
1475-
const pickedUpSearchResults = (
1476-
(await searchForOutdatedDocuments(client, {
1477-
batchSize: 1000,
1478-
targetIndex: 'existing_index_without_mappings',
1479-
outdatedDocumentsQuery: {
1480-
match: { title: { query: 'doc' } },
1481-
},
1482-
})()) as Either.Right<SearchResponse>
1483-
).right.outdatedDocuments;
1484-
expect(pickedUpSearchResults.length).toBe(4);
1443+
const pickedUpSearchResults = await client.search({
1444+
index: 'existing_index_without_mappings',
1445+
size: 1000,
1446+
query: {
1447+
match: { title: { query: 'doc' } },
1448+
},
1449+
});
1450+
expect(pickedUpSearchResults.hits?.hits.length).toBe(4);
14851451
});
14861452
});
14871453

@@ -1903,13 +1869,8 @@ describe('migration actions', () => {
19031869
`);
19041870
});
19051871
it('resolves right even if there were some version_conflict_engine_exception', async () => {
1906-
const existingDocs = (
1907-
(await searchForOutdatedDocuments(client, {
1908-
batchSize: 1000,
1909-
targetIndex: 'existing_index_with_docs',
1910-
outdatedDocumentsQuery: undefined,
1911-
})()) as Either.Right<SearchResponse>
1912-
).right.outdatedDocuments;
1872+
const response = await client.search({ index: 'existing_index_with_docs', size: 1000 });
1873+
const existingDocs = response.hits?.hits as SavedObjectsRawDoc[];
19131874

19141875
const task = bulkOverwriteTransformedDocuments({
19151876
client,

0 commit comments

Comments
 (0)