Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable fields added from unknown saved object types #70951

Merged
merged 7 commits into from
Jul 9, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit tests for disableUnknownTypeMappingFields()
rudolf committed Jul 9, 2020
commit 9235331c54c5ed7b8960779a84532209fd8f55e4
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { disableUnknownTypeMappingFields } from './migration_context';

describe('disableUnknownTypeMappingFields', () => {
const sourceMappings = {
_meta: {
migrationMappingPropertyHashes: {
unknown_type: 'md5hash',
unknown_core_field: 'md5hash',
known_type: 'oldmd5hash',
},
},
properties: {
unknown_type: {
properties: {
unused_field: { type: 'text' },
},
},
unknown_core_field: { type: 'keyword' },
known_type: {
properties: {
field_1: { type: 'text' },
old_field: { type: 'boolean' },
},
},
},
};
const activeMappings = {
_meta: {
migrationMappingPropertyHashes: {
known_type: 'md5hash',
},
},
properties: {
known_type: {
properties: {
new_field: { type: 'binary' },
field_1: { type: 'keyword' },
},
},
},
};
const targetMappings = disableUnknownTypeMappingFields(activeMappings, sourceMappings);

it('disables complex field mappings from unknown types in the source mappings', () => {
expect(targetMappings.properties.unknown_type).toEqual({ dynamic: false, properties: {} });
});

it('retains unknown core field mappings from the source mappings', () => {
expect(targetMappings.properties.unknown_core_field).toEqual({ type: 'keyword' });
});

it('overrides source mappings with known types from active mappings', () => {
expect(targetMappings.properties.known_type).toEqual({
properties: {
new_field: { type: 'binary' },
field_1: { type: 'keyword' }, // was type text in source mappings
// old_field was present in source but ommited in active mappings
},
});
});

it('retains the active mappings _meta ignoring any _meta fields in the source mappings', () => {
expect(targetMappings._meta).toEqual({
migrationMappingPropertyHashes: {
known_type: 'md5hash',
},
});
});
});
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ function createDestContext(
* @param sourceMappings The mappings of index used as the migration source.
* @returns The mappings that should be applied to the target index.
*/
function disableUnknownTypeMappingFields(
export function disableUnknownTypeMappingFields(
activeMappings: IndexMapping,
sourceMappings: IndexMapping
): IndexMapping {