mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
(cherry picked from commit 88eae3ef40
)
Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
parent
b242ba6b8d
commit
2e81f4c1ef
2 changed files with 62 additions and 1 deletions
|
@ -624,4 +624,50 @@ describe('processFields', () => {
|
|||
];
|
||||
expect(processFields(fields)).toEqual(fieldsExpected);
|
||||
});
|
||||
|
||||
test('handle wildcard field', () => {
|
||||
const wildcardFields = [
|
||||
{
|
||||
name: 'a.*.b',
|
||||
type: 'keyword',
|
||||
},
|
||||
{
|
||||
name: 'a.b.*',
|
||||
type: 'scaled_float',
|
||||
},
|
||||
];
|
||||
|
||||
expect(processFields(wildcardFields)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"name": "a",
|
||||
"type": "group",
|
||||
"fields": [
|
||||
{
|
||||
"name": "*",
|
||||
"type": "group",
|
||||
"fields": [
|
||||
{
|
||||
"name": "b",
|
||||
"type": "object",
|
||||
"object_type": "keyword"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"type": "group",
|
||||
"fields": [
|
||||
{
|
||||
"name": "*",
|
||||
"type": "object",
|
||||
"object_type": "scaled_float"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -246,8 +246,23 @@ export const getField = (fields: Fields, pathNames: string[]): Field | undefined
|
|||
return undefined;
|
||||
};
|
||||
|
||||
export function processFieldsWithWildcard(fields: Fields): Fields {
|
||||
const newFields: Fields = [];
|
||||
for (const field of fields) {
|
||||
const hasWildcard = field.name.includes('*');
|
||||
const hasObjectType = field.object_type;
|
||||
if (hasWildcard && !hasObjectType) {
|
||||
newFields.push({ ...field, type: 'object', object_type: field.type });
|
||||
} else {
|
||||
newFields.push({ ...field });
|
||||
}
|
||||
}
|
||||
return newFields;
|
||||
}
|
||||
|
||||
export function processFields(fields: Fields): Fields {
|
||||
const expandedFields = expandFields(fields);
|
||||
const processedFields = processFieldsWithWildcard(fields);
|
||||
const expandedFields = expandFields(processedFields);
|
||||
const dedupedFields = dedupFields(expandedFields);
|
||||
return validateFields(dedupedFields, dedupedFields);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue