Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Always show unmapped fields #91735

Merged
merged 5 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ function discoverController($route, $scope, Promise) {
history.push('/');
};

const showUnmappedFieldsDefaultValue = $scope.useNewFieldsApi && !!$scope.opts.savedSearch.pre712;
const showUnmappedFieldsDefaultValue = $scope.useNewFieldsApi;
let showUnmappedFields = showUnmappedFieldsDefaultValue;

const onChangeUnmappedFields = (value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class SearchEmbeddable
const useNewFieldsApi = !this.services.uiSettings.get(SEARCH_FIELDS_FROM_SOURCE, false);
if (!this.searchScope) return;

const { searchSource, pre712 } = this.savedSearch;
const { searchSource } = this.savedSearch;

// Abort any in-progress requests
if (this.abortController) this.abortController.abort();
Expand All @@ -308,10 +308,7 @@ export class SearchEmbeddable
);
if (useNewFieldsApi) {
searchSource.removeField('fieldsFromSource');
const fields: Record<string, string> = { field: '*' };
if (pre712) {
fields.include_unmapped = 'true';
}
const fields: Record<string, string> = { field: '*', include_unmapped: 'true' };
searchSource.setField('fields', [fields]);
} else {
searchSource.removeField('fields');
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/discover/public/saved_searches/_saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
grid: 'object',
sort: 'keyword',
version: 'integer',
pre712: 'boolean',
};
// Order these fields to the top, the rest are alphabetical
public static fieldOrder = ['title', 'description'];
Expand All @@ -42,7 +41,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
grid: 'object',
sort: 'keyword',
version: 'integer',
pre712: 'boolean',
},
searchSource: true,
defaults: {
Expand All @@ -52,7 +50,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
hits: 0,
sort: [],
version: 1,
pre712: false,
},
});
this.showInRecentlyAccessed = true;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/discover/public/saved_searches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface SavedSearch {
save: (saveOptions: SavedObjectSaveOpts) => Promise<string>;
lastSavedTitle?: string;
copyOnSave?: boolean;
pre712?: boolean;
hideChart?: boolean;
}
export interface SavedSearchLoader {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/discover/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const searchSavedObjectType: SavedObjectsType = {
title: { type: 'text' },
grid: { type: 'object', enabled: false },
version: { type: 'integer' },
pre712: { type: 'boolean' },
},
},
migrations: searchMigrations as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,41 +350,4 @@ Object {
testMigrateMatchAllQuery(migrationFn);
});
});

describe('7.12.0', () => {
const migrationFn = searchMigrations['7.12.0'];

describe('migrateExistingSavedSearch', () => {
it('should add a new flag to existing saved searches', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {},
},
},
savedObjectMigrationContext
);
const migratedPre712Flag = migratedDoc.attributes.pre712;

expect(migratedPre712Flag).toEqual(true);
});

it('should not modify a flag if it already exists', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {},
pre712: false,
},
},
savedObjectMigrationContext
);
const migratedPre712Flag = migratedDoc.attributes.pre712;

expect(migratedPre712Flag).toEqual(false);
});
});
});
});
19 changes: 0 additions & 19 deletions src/plugins/discover/server/saved_objects/search_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,9 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn<any, any> = (doc) =
};
};

const migrateExistingSavedSearch: SavedObjectMigrationFn<any, any> = (doc) => {
if (!doc.attributes) {
return doc;
}
const pre712 = doc.attributes.pre712;
// pre712 already has a value
if (pre712 !== undefined) {
return doc;
}
return {
...doc,
attributes: {
...doc.attributes,
pre712: true,
},
};
};

export const searchMigrations = {
'6.7.2': flow(migrateMatchAllQuery),
'7.0.0': flow(setNewReferences),
'7.4.0': flow(migrateSearchSortToNestedArray),
'7.9.3': flow(migrateMatchAllQuery),
'7.12.0': flow(migrateExistingSavedSearch),
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await esArchiver.unload('unmapped_fields');
});

it('unmapped fields do not exist on a new saved search', async () => {
it('unmapped fields exist on a new saved search', async () => {
const expectedHitCount = '4';
await retry.try(async function () {
expect(await PageObjects.discover.getHitCount()).to.be(expectedHitCount);
Expand All @@ -46,13 +46,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// message is a mapped field
expect(allFields.includes('message')).to.be(true);
// sender is not a mapped field
expect(allFields.includes('sender')).to.be(false);
});

it('unmapped fields toggle does not exist on a new saved search', async () => {
await PageObjects.discover.openSidebarFieldFilter();
await testSubjects.existOrFail('filterSelectionPanel');
await testSubjects.missingOrFail('unmappedFieldsSwitch');
expect(allFields.includes('sender')).to.be(true);
});

it('unmapped fields exist on an existing saved search', async () => {
Expand Down