Skip to content

Commit 88eae3e

Browse files
authored
[Fleet] Generate dynamic template mappings for field with wildcard in name (#137978)
1 parent 6bd3c73 commit 88eae3e

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

x-pack/plugins/fleet/server/services/epm/fields/field.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,50 @@ describe('processFields', () => {
624624
];
625625
expect(processFields(fields)).toEqual(fieldsExpected);
626626
});
627+
628+
test('handle wildcard field', () => {
629+
const wildcardFields = [
630+
{
631+
name: 'a.*.b',
632+
type: 'keyword',
633+
},
634+
{
635+
name: 'a.b.*',
636+
type: 'scaled_float',
637+
},
638+
];
639+
640+
expect(processFields(wildcardFields)).toMatchInlineSnapshot(`
641+
[
642+
{
643+
"name": "a",
644+
"type": "group",
645+
"fields": [
646+
{
647+
"name": "*",
648+
"type": "group",
649+
"fields": [
650+
{
651+
"name": "b",
652+
"type": "object",
653+
"object_type": "keyword"
654+
}
655+
]
656+
},
657+
{
658+
"name": "b",
659+
"type": "group",
660+
"fields": [
661+
{
662+
"name": "*",
663+
"type": "object",
664+
"object_type": "scaled_float"
665+
}
666+
]
667+
}
668+
]
669+
}
670+
]
671+
`);
672+
});
627673
});

x-pack/plugins/fleet/server/services/epm/fields/field.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,23 @@ export const getField = (fields: Fields, pathNames: string[]): Field | undefined
246246
return undefined;
247247
};
248248

249+
export function processFieldsWithWildcard(fields: Fields): Fields {
250+
const newFields: Fields = [];
251+
for (const field of fields) {
252+
const hasWildcard = field.name.includes('*');
253+
const hasObjectType = field.object_type;
254+
if (hasWildcard && !hasObjectType) {
255+
newFields.push({ ...field, type: 'object', object_type: field.type });
256+
} else {
257+
newFields.push({ ...field });
258+
}
259+
}
260+
return newFields;
261+
}
262+
249263
export function processFields(fields: Fields): Fields {
250-
const expandedFields = expandFields(fields);
264+
const processedFields = processFieldsWithWildcard(fields);
265+
const expandedFields = expandFields(processedFields);
251266
const dedupedFields = dedupFields(expandedFields);
252267
return validateFields(dedupedFields, dedupedFields);
253268
}

0 commit comments

Comments
 (0)