Skip to content

Commit

Permalink
[Discover] Show unmapped fields when reading from source (#91719)
Browse files Browse the repository at this point in the history
* [Discover] Show unmapped fields when reading from source

* Adding a unit test
  • Loading branch information
Maja Grubic authored Feb 18, 2021
1 parent 6defaed commit 94f0bd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const fieldCounts = {
category: 1,
currency: 1,
customer_birth_date: 1,
unknown_field: 1,
};

describe('group_fields', function () {
Expand Down Expand Up @@ -232,7 +233,7 @@ describe('group_fields', function () {

const actual = groupFields(
fieldsWithUnmappedField as IndexPatternField[],
['customer_birth_date', 'currency', 'unknown'],
['customer_birth_date', 'currency'],
5,
fieldCounts,
fieldFilterState,
Expand All @@ -241,4 +242,30 @@ describe('group_fields', function () {
);
expect(actual.unpopular).toEqual([]);
});

it('includes unmapped fields when reading from source', function () {
const fieldFilterState = getDefaultFieldFilter();
const fieldsWithUnmappedField = [...fields];
fieldsWithUnmappedField.push({
name: 'unknown_field',
type: 'unknown',
esTypes: ['unknown'],
count: 0,
scripted: false,
searchable: false,
aggregatable: false,
readFromDocValues: false,
});

const actual = groupFields(
fieldsWithUnmappedField as IndexPatternField[],
['customer_birth_date', 'currency'],
5,
fieldCounts,
fieldFilterState,
false,
undefined
);
expect(actual.unpopular.map((field) => field.name)).toEqual(['unknown_field']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export function groupFields(
} else if (field.type !== '_source') {
// do not show unmapped fields unless explicitly specified
// do not add subfields to this list
if ((field.type !== 'unknown' || showUnmappedFields) && !isSubfield) {
if (useNewFieldsApi && (field.type !== 'unknown' || showUnmappedFields) && !isSubfield) {
result.unpopular.push(field);
} else if (!useNewFieldsApi) {
result.unpopular.push(field);
}
}
Expand Down

0 comments on commit 94f0bd9

Please sign in to comment.