Skip to content

Commit

Permalink
parse types in fielddata (opendistro-for-elasticsearch#284)
Browse files Browse the repository at this point in the history
* parse types in fielddata

* remove useless return
  • Loading branch information
ylwu-amzn authored and yizheliu-amazon committed Aug 28, 2020
1 parent f0de278 commit 0e2107a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
49 changes: 49 additions & 0 deletions public/redux/reducers/__tests__/mapper.test.ts
Original file line number Diff line number Diff line change
@@ -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'],
});
});
});
});
11 changes: 11 additions & 0 deletions public/redux/reducers/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0e2107a

Please sign in to comment.