Skip to content

Commit

Permalink
[Fleet] Add support for constant_keyword "value" in package field def…
Browse files Browse the repository at this point in the history
…initions (elastic#103000)

This enables Fleet to accept package field definitions that declare a constant "value"
for `constant_keyword` fields. Fleet will generate an index template for the constant_keyword
field that contains the `value` attribute.

Relates: elastic/package-spec#194

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
andrewkroh and kibanamachine committed Jun 25, 2021
1 parent 4b20ff3 commit bc8ba83
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.

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

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
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
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
Expand Up @@ -20,4 +20,7 @@
object_type: integer
- name: invalidarray
type: array
- name: cycle_type
type: constant_keyword
value: bicycle

0 comments on commit bc8ba83

Please sign in to comment.