Skip to content

Commit

Permalink
Change check for isQueryFilter back to original, but acknowledge quer…
Browse files Browse the repository at this point in the history
…y_string property could be undefined. (elastic#43356)
  • Loading branch information
stacey-gammon committed Aug 15, 2019
1 parent 838bb39 commit 06b02f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('dashboard migration 7.3.0 migrates filters to query on search source', ()
});

// See https://github.com/elastic/kibana/issues/41240 - this can happen.
test('dashboard migration 7.3.0 does not migrate filters to query on search source when there is no query string property', () => {
test('dashboard migration 7.3.0 migrates filters to query on search source when there is no query string property', () => {
const doc: DashboardDocPre700 = {
id: 'AWviOturFv4p9HkVSIgn',
type: 'dashboard',
Expand All @@ -100,7 +100,7 @@ test('dashboard migration 7.3.0 does not migrate filters to query on search sour
const newDoc = migrations.dashboard['7.3.0'](doc700, mockLogger);

const parsedSearchSource = JSON.parse(newDoc.attributes.kibanaSavedObjectMeta.searchSourceJSON);
expect(parsedSearchSource.filter.length).toBe(1);
expect(parsedSearchSource.filter.length).toBe(0);
expect(parsedSearchSource.query.query).toBe('');

expect(newDoc.attributes.uiStateJSON).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Pre600FilterQuery {
// pre 6.0.0 global query:queryString:options were stored per dashboard and would
// be applied even if the setting was subsequently removed from the advanced
// settings. This is considered a bug, and this migration will fix that behavior.
query: { query_string: { query: string } & { [key: string]: unknown } };
query: { query_string?: { query: string } & { [key: string]: unknown } };
}

export interface SearchSourcePre600 {
Expand All @@ -41,9 +41,7 @@ export interface SearchSource730 {
}

function isQueryFilter(filter: Filter | { query: unknown }): filter is Pre600FilterQuery {
return (
filter.query && !(filter as Filter).meta && (filter as Pre600FilterQuery).query.query_string
);
return filter.query && !(filter as Filter).meta;
}

export function moveFiltersToQuery(
Expand All @@ -67,7 +65,7 @@ export function moveFiltersToQuery(
searchSource.filter.forEach(filter => {
if (isQueryFilter(filter)) {
searchSource730.query = {
query: filter.query.query_string.query,
query: filter.query.query_string ? filter.query.query_string.query : '',
language: 'lucene',
};
} else {
Expand Down

0 comments on commit 06b02f4

Please sign in to comment.