Skip to content

Commit

Permalink
Merge pull request #144 from social-native/fix/empty-mapping
Browse files Browse the repository at this point in the history
Fix empty mapping
  • Loading branch information
markrsocialnative authored May 7, 2021
2 parents f45b3ef + 5576529 commit d217700
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elastic-composer",
"version": "4.6.1",
"version": "4.6.2",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/mapping_parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ test('it should work when mappings have a "dynamic" field', () => {
'agg_historic_percent_approved_invite_to_submitted.all_time': 'double'
});
});

test('it should work when mappings is empty', () => {
const fakeMapping = { 'creator-crm-testing': { mappings: {} } };
const actual = MappingParser.flattenMappings710(fakeMapping);
expect(actual).toEqual({})

})
3 changes: 3 additions & 0 deletions src/mapping_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default class MappingParser {
public static flattenMappings710(rawMappings: ESMapping710): Record<string, ESMappingType> {
let flattenedMappings = {};
Object.values(rawMappings).forEach(({mappings}) => {
if (!mappings.properties) {
return;
}
flattenedMappings = {
...flattenedMappings,
...MappingParser.flattenMappingProperty(mappings.properties)
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export type ESMapping710 = {
[index: string]: {
mappings: {
dynamic?: string;
properties: ESMappingProperties
properties?: ESMappingProperties
}
}
}

0 comments on commit d217700

Please sign in to comment.