diff --git a/src/plugins/saved_objects_finder/public/finder/saved_object_finder.tsx b/src/plugins/saved_objects_finder/public/finder/saved_object_finder.tsx index b280e626467d..86940d52a81b 100644 --- a/src/plugins/saved_objects_finder/public/finder/saved_object_finder.tsx +++ b/src/plugins/saved_objects_finder/public/finder/saved_object_finder.tsx @@ -349,6 +349,9 @@ export class SavedObjectFinderUi extends React.Component< box: { incremental: true, 'data-test-subj': 'savedObjectFinderSearchInput', + schema: { + recognizedFields: ['type', 'tag'], + }, }, filters: this.props.showFilter ? [ diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap index 7e88de9674cc..bc0eda7e6d5a 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap @@ -6,6 +6,12 @@ exports[`Table prevents hidden saved objects from being deleted 1`] = ` box={ Object { "data-test-subj": "savedObjectSearchBar", + "schema": Object { + "recognizedFields": Array [ + "type", + "tag", + ], + }, } } filters={ @@ -234,6 +240,12 @@ exports[`Table should render normally 1`] = ` box={ Object { "data-test-subj": "savedObjectSearchBar", + "schema": Object { + "recognizedFields": Array [ + "type", + "tag", + ], + }, } } filters={ diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index dbd9b2a55060..a32a1e9e958e 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -392,7 +392,12 @@ export class Table extends PureComponent { {activeActionContents} { const searchParams = parseSearchParams('tag:((()^invalid'); expect(searchParams).toEqual({ term: 'tag:((()^invalid', - filters: { - unknowns: {}, - }, + filters: {}, }); }); @@ -33,7 +31,6 @@ describe('parseSearchParams', () => { expect(searchParams.filters).toEqual({ tags: undefined, types: undefined, - unknowns: {}, }); }); @@ -44,20 +41,16 @@ describe('parseSearchParams', () => { filters: { tags: ['foo', 'dolly'], types: ['bar'], - unknowns: {}, }, }); }); - it('handles unknowns field clauses', () => { + it('considers unknown field clauses to be part of the raw search term', () => { const searchParams = parseSearchParams('tag:foo unknown:bar hello'); expect(searchParams).toEqual({ - term: 'hello', + term: 'unknown:bar hello', filters: { tags: ['foo'], - unknowns: { - unknown: ['bar'], - }, }, }); }); @@ -69,7 +62,6 @@ describe('parseSearchParams', () => { filters: { tags: ['foo', 'bar'], types: ['dash', 'board'], - unknowns: {}, }, }); }); @@ -81,7 +73,6 @@ describe('parseSearchParams', () => { filters: { tags: ['42', 'true'], types: ['69', 'false'], - unknowns: {}, }, }); }); diff --git a/x-pack/plugins/global_search_bar/public/search_syntax/parse_search_params.ts b/x-pack/plugins/global_search_bar/public/search_syntax/parse_search_params.ts index 989accdf2ea1..1df6c1123a32 100644 --- a/x-pack/plugins/global_search_bar/public/search_syntax/parse_search_params.ts +++ b/x-pack/plugins/global_search_bar/public/search_syntax/parse_search_params.ts @@ -17,32 +17,24 @@ const aliasMap = { }; export const parseSearchParams = (term: string): ParsedSearchParams => { + const recognizedFields = knownFilters.concat(...Object.values(aliasMap)); let query: Query; try { - query = Query.parse(term); + query = Query.parse(term, { + schema: { recognizedFields }, + }); } catch (e) { // if the query fails to parse, we just perform the search against the raw search term. return { term, - filters: { - unknowns: {}, - }, + filters: {}, }; } const searchTerm = getSearchTerm(query); const filterValues = applyAliases(getFieldValueMap(query), aliasMap); - const unknownFilters = [...filterValues.entries()] - .filter(([key]) => !knownFilters.includes(key)) - .reduce((unknowns, [key, value]) => { - return { - ...unknowns, - [key]: value, - }; - }, {} as Record); - const tags = filterValues.get('tag'); const types = filterValues.get('type'); @@ -51,7 +43,6 @@ export const parseSearchParams = (term: string): ParsedSearchParams => { filters: { tags: tags ? valuesToString(tags) : undefined, types: types ? valuesToString(types) : undefined, - unknowns: unknownFilters, }, }; }; diff --git a/x-pack/plugins/global_search_bar/public/search_syntax/types.ts b/x-pack/plugins/global_search_bar/public/search_syntax/types.ts index dc931a469fd7..7b1ce5b762c8 100644 --- a/x-pack/plugins/global_search_bar/public/search_syntax/types.ts +++ b/x-pack/plugins/global_search_bar/public/search_syntax/types.ts @@ -27,9 +27,5 @@ export interface ParsedSearchParams { * Aggregation of `type` and `types` field clauses */ types?: FilterValues; - /** - * All unknown field clauses - */ - unknowns: Record; }; }