Skip to content

Commit

Permalink
Test importing from data/public and casting to ES Field Types.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Nov 15, 2019
1 parent 0ba8ea0 commit 73fdbd6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/plugins/kibana_utils/public/field_mapping/mapping_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ import { ES_FIELD_TYPES } from '../../../data/public';
/** @private */
type ShorthandFieldMapObject = FieldMappingSpec | ES_FIELD_TYPES | 'json';

const json: FieldMappingSpec = {
type: 'text' as ES_FIELD_TYPES,
_serialize(v) {
if (v) return JSON.stringify(v);
},
_deserialize(v) {
if (v) return JSON.parse(v);
},
};

/** @public */
export const expandShorthand = (sh: Record<string, ShorthandFieldMapObject>): MappingObject => {
return mapValues<Record<string, ShorthandFieldMapObject>>(sh, (val: ShorthandFieldMapObject) => {
const fieldMap = isString(val) ? { type: val } : val;
const json: FieldMappingSpec = {
type: ES_FIELD_TYPES.TEXT,
_serialize(v) {
if (v) return JSON.stringify(v);
},
_deserialize(v) {
if (v) return JSON.parse(v);
},
};

return fieldMap.type === 'json' ? json : fieldMap;
}) as MappingObject;
Expand Down

0 comments on commit 73fdbd6

Please sign in to comment.