handle source index without any mappings (#112664)

This commit is contained in:
Pierre Gayvallet 2021-09-21 20:19:34 +02:00 committed by GitHub
parent 659b295391
commit 65ec86da66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -74,4 +74,18 @@ describe('disableUnknownTypeMappingFields', () => {
},
});
});
it('does not fail if the source mapping does not have `properties` defined', () => {
const missingPropertiesMappings = {
...sourceMappings,
properties: undefined,
};
const result = disableUnknownTypeMappingFields(
activeMappings,
// @ts-expect-error `properties` should not be undefined
missingPropertiesMappings
);
expect(Object.keys(result.properties)).toEqual(['known_type']);
});
});

View file

@ -154,7 +154,7 @@ export function disableUnknownTypeMappingFields(
): IndexMapping {
const targetTypes = Object.keys(activeMappings.properties);
const disabledTypesProperties = Object.keys(sourceMappings.properties)
const disabledTypesProperties = Object.keys(sourceMappings.properties ?? {})
.filter((sourceType) => {
const isObjectType = 'properties' in sourceMappings.properties[sourceType];
// Only Object/Nested datatypes can be excluded from the field count by