Skip to content

Commit

Permalink
Update KQL field autocompletion to suggest fields that match search (e…
Browse files Browse the repository at this point in the history
…lastic#92559) (elastic#93302)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
lukasolson and kibanamachine authored Mar 2, 2021
1 parent 5dda62e commit ddab9f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ describe('Kuery field suggestions', () => {
expect(suggestions.find(({ text }) => text === 'machine.os ')).toBeDefined();
});

test('should field names that match the search', async () => {
const prefix = 'machi';
const suffix = 'ne.os';
const suggestions = await getSuggestions(
querySuggestionsArgs,
mockKueryNode({ prefix, suffix })
);

expect(suggestions.find(({ text }) => text === 'machine.os ')).toBeDefined();
});

test('should return field names that start with the query first', async () => {
const prefix = 'e';
const suffix = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export const setupGetFieldSuggestions: KqlQuerySuggestionProvider<QuerySuggestio
field.subType &&
field.subType.nested &&
field.subType.nested.path.includes(nestedPath))) &&
field.name.toLowerCase().includes(search) &&
field.name !== search
field.name.toLowerCase().includes(search)
);
});
const sortedFields = sortPrefixFirst(matchingFields.sort(keywordComparator), search, 'name');
Expand Down

0 comments on commit ddab9f2

Please sign in to comment.