Skip to content

Commit

Permalink
[EPM] Handle constant_keyword type in KB index patterns and ES index …
Browse files Browse the repository at this point in the history
…templates (#64876) (#64882)

* Unit-test constant_keyword mapping generation

* Treat constant_keyword as string in kibana index patterns
  • Loading branch information
skh authored Apr 30, 2020
1 parent 2fddf9a commit 4442e46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,21 @@ test('tests processing object field with property, reverse order', () => {
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(objectFieldWithPropertyReversedMapping));
});

test('tests constant_keyword field type handling', () => {
const constantKeywordLiteralYaml = `
- name: constantKeyword
type: constant_keyword
`;
const constantKeywordMapping = {
properties: {
constantKeyword: {
type: 'constant_keyword',
},
},
};
const fields: Field[] = safeLoad(constantKeywordLiteralYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(constantKeywordMapping));
});
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe('creating index patterns from yaml fields', () => {
{ fields: [{ name: 'testField', type: 'text' }], expect: 'string' },
{ fields: [{ name: 'testField', type: 'date' }], expect: 'date' },
{ fields: [{ name: 'testField', type: 'geo_point' }], expect: 'geo_point' },
{ fields: [{ name: 'testField', type: 'constant_keyword' }], expect: 'string' },
];

tests.forEach(test => {
Expand Down Expand Up @@ -191,6 +192,7 @@ describe('creating index patterns from yaml fields', () => {
attr: 'aggregatable',
},
{ fields: [{ name, type: 'keyword' }], expect: true, attr: 'aggregatable' },
{ fields: [{ name, type: 'constant_keyword' }], expect: true, attr: 'aggregatable' },
{ fields: [{ name, type: 'text', aggregatable: true }], expect: false, attr: 'aggregatable' },
{ fields: [{ name, type: 'text' }], expect: false, attr: 'aggregatable' },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const typeMap: TypeMap = {
date: 'date',
ip: 'ip',
boolean: 'boolean',
constant_keyword: 'string',
};

export interface IndexPatternField {
Expand Down

0 comments on commit 4442e46

Please sign in to comment.