don't include group fields with no child fields in index pattern (#69457)
This commit is contained in:
parent
2436e2c9a6
commit
f4b0d5cbbc
|
@ -611,7 +611,7 @@ exports[`creating index patterns from yaml fields createIndexPatternFields funct
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`creating index patterns from yaml fields flattenFields function flattens recursively and handles copying alias fields: flattenFields 1`] = `
|
||||
exports[`creating index patterns from yaml fields flattenFields function flattens recursively and handles copying alias fields flattenFields matches snapshot: flattenFields 1`] = `
|
||||
[
|
||||
{
|
||||
"name": "coredns.id",
|
||||
|
|
|
@ -56,9 +56,15 @@ describe('creating index patterns from yaml fields', () => {
|
|||
expect(indexPattern).toMatchSnapshot('createIndexPattern');
|
||||
});
|
||||
|
||||
test('flattenFields function flattens recursively and handles copying alias fields', () => {
|
||||
const flattened = flattenFields(fields);
|
||||
expect(flattened).toMatchSnapshot('flattenFields');
|
||||
describe('flattenFields function flattens recursively and handles copying alias fields', () => {
|
||||
test('a field of type group with no nested fields is skipped', () => {
|
||||
const flattened = flattenFields([{ name: 'nginx', type: 'group' }]);
|
||||
expect(flattened.length).toBe(0);
|
||||
});
|
||||
test('flattenFields matches snapshot', () => {
|
||||
const flattened = flattenFields(fields);
|
||||
expect(flattened).toMatchSnapshot('flattenFields');
|
||||
});
|
||||
});
|
||||
|
||||
describe('dedupFields', () => {
|
||||
|
|
|
@ -307,6 +307,10 @@ export const transformField = (field: Field, i: number, fields: Fields): IndexPa
|
|||
export const flattenFields = (allFields: Fields): Fields => {
|
||||
const flatten = (fields: Fields): Fields =>
|
||||
fields.reduce<Field[]>((acc, field) => {
|
||||
// if this is a group fields with no fields, skip the field
|
||||
if (field.type === 'group' && !field.fields?.length) {
|
||||
return acc;
|
||||
}
|
||||
// recurse through nested fields
|
||||
if (field.type === 'group' && field.fields?.length) {
|
||||
// skip if field.enabled is not explicitly set to false
|
||||
|
|
|
@ -116,3 +116,5 @@
|
|||
type: keyword
|
||||
- name: text
|
||||
type: text
|
||||
- name: nginx
|
||||
type: group
|
Loading…
Reference in a new issue