Skip to content

Commit

Permalink
[Fleet] index templates - add support for wildcard multi-fields (#121088
Browse files Browse the repository at this point in the history
)

* fleet - index templates - add support for wildcard multi-fields

* adjust types

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dominiqueclarke and kibanamachine authored Dec 13, 2021
1 parent 16af3e6 commit 797bc49
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,40 @@ describe('EPM template', () => {
expect(mappings).toEqual(keywordWithMultiFieldsMapping);
});

it('tests processing wildcard field with multi fields', () => {
const keywordWithMultiFieldsLiteralYml = `
- name: keywordWithMultiFields
type: wildcard
multi_fields:
- name: raw
type: keyword
- name: indexed
type: text
`;

const keywordWithMultiFieldsMapping = {
properties: {
keywordWithMultiFields: {
ignore_above: 1024,
type: 'wildcard',
fields: {
raw: {
ignore_above: 1024,
type: 'keyword',
},
indexed: {
type: 'text',
},
},
},
},
};
const fields: Field[] = safeLoad(keywordWithMultiFieldsLiteralYml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(keywordWithMultiFieldsMapping);
});

it('tests processing object field with no other attributes', () => {
const objectFieldLiteralYml = `
- name: objectField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ export function generateMappings(fields: Field[]): IndexTemplateMappings {
fieldProps.fields = generateMultiFields(field.multi_fields);
}
break;
case 'wildcard':
const wildcardMapping = generateWildcardMapping(field);
fieldProps = { ...fieldProps, ...wildcardMapping, type: 'wildcard' };
if (field.multi_fields) {
fieldProps.fields = generateMultiFields(field.multi_fields);
}
break;
case 'constant_keyword':
fieldProps.type = field.type;
if (field.value) {
Expand Down Expand Up @@ -270,6 +277,19 @@ function generateTextMapping(field: Field): IndexTemplateMapping {
return mapping;
}

function generateWildcardMapping(field: Field): IndexTemplateMapping {
const mapping: IndexTemplateMapping = {
ignore_above: DEFAULT_IGNORE_ABOVE,
};
if (field.null_value) {
mapping.null_value = field.null_value;
}
if (field.ignore_above) {
mapping.ignore_above = field.ignore_above;
}
return mapping;
}

function getDefaultProperties(field: Field): Properties {
const properties: Properties = {};

Expand Down
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 @@ -34,6 +34,7 @@ export interface Field {
dynamic?: 'strict' | boolean;
include_in_parent?: boolean;
include_in_root?: boolean;
null_value?: string;

// Meta fields
metric_type?: string;
Expand Down

0 comments on commit 797bc49

Please sign in to comment.