From 0e2107aa26366212907aa2d76e8ea5b0d0f0f925 Mon Sep 17 00:00:00 2001 From: Yaliang <49084640+ylwu-amzn@users.noreply.github.com> Date: Mon, 24 Aug 2020 10:42:07 -0700 Subject: [PATCH] parse types in fielddata (#284) * parse types in fielddata * remove useless return --- .../redux/reducers/__tests__/mapper.test.ts | 49 +++++++++++++++++++ public/redux/reducers/mapper.ts | 11 +++++ 2 files changed, 60 insertions(+) create mode 100644 public/redux/reducers/__tests__/mapper.test.ts diff --git a/public/redux/reducers/__tests__/mapper.test.ts b/public/redux/reducers/__tests__/mapper.test.ts new file mode 100644 index 00000000..a8a143c1 --- /dev/null +++ b/public/redux/reducers/__tests__/mapper.test.ts @@ -0,0 +1,49 @@ +import { getPathsPerDataType } from '../mapper'; + +describe('mapper', () => { + describe('getPathsPerDataType', () => { + test('has fields', async () => { + const mappings = { + test_index: { + mappings: { + properties: { + test: { + properties: { + a: { + properties: { + b: { + type: 'keyword', + eager_global_ordinals: true, + fields: { + raw: { + type: 'integer', + }, + }, + }, + }, + }, + }, + }, + timestamp: { + type: 'date', + format: 'strict_date_time||epoch_millis', + }, + value: { + type: 'float', + }, + }, + }, + }, + }; + const pathsPerDataType = getPathsPerDataType(mappings); + console.log(pathsPerDataType); + + expect(pathsPerDataType).toEqual({ + keyword: ['test.a.b'], + integer: ['test.a.b.raw'], + date: ['timestamp'], + float: ['value'], + }); + }); + }); +}); diff --git a/public/redux/reducers/mapper.ts b/public/redux/reducers/mapper.ts index b84e8713..37e79262 100644 --- a/public/redux/reducers/mapper.ts +++ b/public/redux/reducers/mapper.ts @@ -54,6 +54,17 @@ export function getTypeFromMappings( } else { currentDataTypes[type] = [path]; } + + if (mappings.fields) { + Object.entries(mappings.fields).forEach(([field, value]) => { + currentDataTypes = getTypeFromMappings( + value as Mappings, + currentDataTypes, + resolvePath(path, field) + ); + }); + } + return currentDataTypes; }