Skip to content

Commit ff0df43

Browse files
[Fleet] Add support for constant_keyword "value" in package field definitions (#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>
1 parent 68d8d04 commit ff0df43

6 files changed

Lines changed: 39 additions & 0 deletions

File tree

x-pack/plugins/fleet/server/services/epm/elasticsearch/template/__snapshots__/template.test.ts.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,26 @@ describe('EPM template', () => {
613613
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(constantKeywordMapping));
614614
});
615615

616+
it('tests constant_keyword field type with value', () => {
617+
const constantKeywordLiteralYaml = `
618+
- name: constantKeyword
619+
type: constant_keyword
620+
value: always_the_same
621+
`;
622+
const constantKeywordMapping = {
623+
properties: {
624+
constantKeyword: {
625+
type: 'constant_keyword',
626+
value: 'always_the_same',
627+
},
628+
},
629+
};
630+
const fields: Field[] = safeLoad(constantKeywordLiteralYaml);
631+
const processedFields = processFields(fields);
632+
const mappings = generateMappings(processedFields);
633+
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(constantKeywordMapping));
634+
});
635+
616636
it('processes meta fields', () => {
617637
const metaFieldLiteralYaml = `
618638
- name: fieldWithMetas

x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
150150
fieldProps.fields = generateMultiFields(field.multi_fields);
151151
}
152152
break;
153+
case 'constant_keyword':
154+
fieldProps.type = field.type;
155+
if (field.value) {
156+
fieldProps.value = field.value;
157+
}
158+
break;
153159
case 'object':
154160
fieldProps = { ...fieldProps, ...generateDynamicAndEnabled(field), type: 'object' };
155161
break;

x-pack/plugins/fleet/server/services/epm/fields/__snapshots__/field.test.ts.snap

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/fleet/server/services/epm/fields/field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Field {
1515
name: string;
1616
type?: string;
1717
description?: string;
18+
value?: string;
1819
format?: string;
1920
fields?: Fields;
2021
enabled?: boolean;

x-pack/plugins/fleet/server/services/epm/fields/tests/base.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020
object_type: integer
2121
- name: invalidarray
2222
type: array
23+
- name: cycle_type
24+
type: constant_keyword
25+
value: bicycle
2326

0 commit comments

Comments
 (0)