-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44c7091
commit 397c14c
Showing
9 changed files
with
156 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...core-saved-objects-migration-server-internal/src/core/build_pickup_mappings_query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { buildPickupMappingsQuery } from './build_pickup_mappings_query'; | ||
|
||
describe('buildPickupMappingsQuery', () => { | ||
describe('when no root fields have been updated', () => { | ||
it('builds a boolean query to select the updated types', () => { | ||
const query = buildPickupMappingsQuery({ | ||
rootFields: ['someRootField'], | ||
updatedFields: ['type1', 'type2'], | ||
}); | ||
|
||
expect(query).toEqual({ | ||
bool: { | ||
should: [{ term: { type: 'type1' } }, { term: { type: 'type2' } }], | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when some root fields have been updated', () => { | ||
it('returns undefined', () => { | ||
const query = buildPickupMappingsQuery({ | ||
rootFields: ['someRootField'], | ||
updatedFields: ['type1', 'type2', 'someRootField'], | ||
}); | ||
|
||
expect(query).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...ects/core-saved-objects-migration-server-internal/src/core/build_pickup_mappings_query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const buildPickupMappingsQuery = ({ | ||
rootFields, | ||
updatedFields, | ||
}: { | ||
rootFields: string[]; | ||
updatedFields: string[]; | ||
}): QueryDslQueryContainer | undefined => { | ||
if (updatedFields.some((field) => rootFields.includes(field))) { | ||
// we are updating some root fields, update ALL documents (no filter query) | ||
return undefined; | ||
} | ||
|
||
// at this point, all updated fields correspond to SO types | ||
const updatedTypes = updatedFields; | ||
|
||
return { | ||
bool: { | ||
should: updatedTypes.map((type) => ({ term: { type } })), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters