mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fix a bug where ES sends a string and migrations expect a boolean (#23313)
This commit is contained in:
parent
63d0824991
commit
aac10b0eb8
2 changed files with 30 additions and 3 deletions
|
@ -63,7 +63,30 @@ describe('determineMigrationAction', () => {
|
|||
doc: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
hello: { dynamic: true, goober: 'pea' },
|
||||
hello: { dynamic: 'true', goober: 'pea' },
|
||||
world: { baz: 'bing' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(determineMigrationAction(actual, expected)).toEqual(MigrationAction.None);
|
||||
});
|
||||
|
||||
test('requires no action if mappings differ only by equivalent coerced properties', () => {
|
||||
const actual = {
|
||||
doc: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
hello: { dynamic: 'false', baz: '2', foo: 'bar' },
|
||||
world: { baz: 'bing' },
|
||||
},
|
||||
},
|
||||
};
|
||||
const expected = {
|
||||
doc: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
hello: { dynamic: false, baz: 2, foo: 'bar' },
|
||||
world: { baz: 'bing' },
|
||||
},
|
||||
},
|
||||
|
|
|
@ -74,7 +74,11 @@ function diffSubProperty(actual: any, expected: any): MigrationAction {
|
|||
// We have a leaf property, so we do a comparison. A change (e.g. 'text' -> 'keyword')
|
||||
// should result in a migration.
|
||||
if (typeof actual !== 'object') {
|
||||
return _.isEqual(actual, expected) ? MigrationAction.None : MigrationAction.Migrate;
|
||||
// We perform a string comparison here, because Elasticsearch coerces some primitives
|
||||
// to string (such as dynamic: true and dynamic: 'true'), so we report a mapping
|
||||
// equivalency if the string comparison checks out. This does mean that {} === '[object Object]'
|
||||
// by this logic, but that is an edge case which should not occur in mapping definitions.
|
||||
return `${actual}` === `${expected}` ? MigrationAction.None : MigrationAction.Migrate;
|
||||
}
|
||||
|
||||
// Recursively compare the sub properties
|
||||
|
@ -87,5 +91,5 @@ function diffSubProperty(actual: any, expected: any): MigrationAction {
|
|||
}
|
||||
|
||||
function isDynamic(prop: any) {
|
||||
return prop.dynamic === true || prop.dynamic === 'true';
|
||||
return prop && `${prop.dynamic}` === 'true';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue