Skip to content

Commit

Permalink
Revert "[Fleet] Expand subfields of nested objects when generating te…
Browse files Browse the repository at this point in the history
…mplate (#191730)"

This reverts commit cdb1eb8.
  • Loading branch information
jsoriano committed Sep 2, 2024
1 parent ab6bb9c commit f31ffec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -920,106 +920,6 @@ describe('EPM template', () => {
expect(mappings).toEqual(expectedMapping);
});

it('tests processing nested field with subobject, nested field first', () => {
const nestedYaml = `
- name: a
type: nested
include_in_parent: true
- name: a.b
type: group
fields:
- name: c
type: keyword
`;
const expectedMapping = {
properties: {
a: {
include_in_parent: true,
type: 'nested',
properties: {
b: {
properties: {
c: {
ignore_above: 1024,
type: 'keyword',
},
},
},
},
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});

it('tests processing nested field with subfields', () => {
const nestedYaml = `
- name: a
type: nested
include_in_parent: true
fields:
- name: b
type: keyword
`;
const expectedMapping = {
properties: {
a: {
include_in_parent: true,
type: 'nested',
properties: {
b: {
ignore_above: 1024,
type: 'keyword',
},
},
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});

it('tests processing nested field with subobjects', () => {
const nestedYaml = `
- name: a
type: nested
include_in_parent: true
fields:
- name: b
type: group
fields:
- name: c
type: keyword
`;
const expectedMapping = {
properties: {
a: {
include_in_parent: true,
type: 'nested',
properties: {
b: {
properties: {
c: {
ignore_above: 1024,
type: 'keyword',
},
},
},
},
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
});

it('tests processing nested leaf field with properties', () => {
const nestedYaml = `
- name: a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,9 @@ function _generateMappings(
fieldProps.subobjects = mappings.subobjects;
}
break;
case 'nested':
case 'group-nested':
fieldProps = { ...generateNestedProps(field), type: 'nested' };
if (field.fields) {
fieldProps.properties = _generateMappings(
fieldProps = {
properties: _generateMappings(
field.fields!,
{
...ctx,
Expand All @@ -526,8 +524,10 @@ function _generateMappings(
: field.name,
},
isIndexModeTimeSeries
).properties;
}
).properties,
...generateNestedProps(field),
type: 'nested',
};
break;
case 'integer':
fieldProps.type = 'long';
Expand Down Expand Up @@ -564,6 +564,9 @@ function _generateMappings(
fieldProps.value = field.value;
}
break;
case 'nested':
fieldProps = { ...fieldProps, ...generateNestedProps(field), type: 'nested' };
break;
case 'array':
// this assumes array fields were validated in an earlier step
// adding an array field with no object_type would result in an error
Expand Down
31 changes: 0 additions & 31 deletions x-pack/plugins/fleet/server/services/epm/fields/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,37 +273,6 @@ describe('processFields', () => {
expect(processFields(nested)).toEqual(nestedExpanded);
});

test('correctly handles properties of nested type fields with subfields', () => {
const nested = [
{
name: 'a',
type: 'nested',
dynamic: true,
fields: [
{
name: 'b',
type: 'keyword',
},
],
},
];

const nestedExpanded = [
{
name: 'a',
type: 'nested',
dynamic: true,
fields: [
{
name: 'b',
type: 'keyword',
},
],
},
];
expect(processFields(nested)).toEqual(nestedExpanded);
});

test('correctly handles properties of nested and object type fields together', () => {
const fields = [
{
Expand Down

0 comments on commit f31ffec

Please sign in to comment.