Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Add support for constant_keyword "value" in package field defs #103000

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ describe('EPM template', () => {
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(constantKeywordMapping));
});

it('tests constant_keyword field type with value', () => {
const constantKeywordLiteralYaml = `
- name: constantKeyword
type: constant_keyword
value: always_the_same
`;
const constantKeywordMapping = {
properties: {
constantKeyword: {
type: 'constant_keyword',
value: 'always_the_same',
},
},
};
const fields: Field[] = safeLoad(constantKeywordLiteralYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(constantKeywordMapping));
});

it('processes meta fields', () => {
const metaFieldLiteralYaml = `
- name: fieldWithMetas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
fieldProps.fields = generateMultiFields(field.multi_fields);
}
break;
case 'constant_keyword':
fieldProps.type = field.type;
if (field.value) {
fieldProps.value = field.value;
}
break;
case 'object':
fieldProps = { ...fieldProps, ...generateDynamicAndEnabled(field), type: 'object' };
break;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x-pack/plugins/fleet/server/services/epm/fields/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Field {
name: string;
type?: string;
description?: string;
value?: string;
format?: string;
fields?: Fields;
enabled?: boolean;
Expand Down