[ES|QL] Add context-aware suggestion ordering with categorization#243312
[ES|QL] Add context-aware suggestion ordering with categorization#243312bartoval merged 12 commits intoelastic:mainfrom
Conversation
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { |
There was a problem hiding this comment.
I’m not sure we want this level of granularity for operators
There was a problem hiding this comment.
I dont think we do either
|
|
||
| // Context-specific priority adjustments (negative = boost up, positive = push down) | ||
| const CONTEXT_BOOSTS: Record<string, Partial<Record<SuggestionCategory, number>>> = { | ||
| STATS: { |
There was a problem hiding this comment.
These are just examples to show how to change priorities per command
7eb7f7b to
3dae845
Compare
768af6f to
f0732b3
Compare
f0732b3 to
2475929
Compare
|
Pinging @elastic/kibana-esql (Team:ESQL) |
124ff5e to
9f81fb4
Compare
|
@bartoval can you use enum for the categories and reuse it everywhere? |
4059e13 to
e6dec13
Compare
e6dec13 to
75a9ad2
Compare
| // Structure: { 'COMMAND' } or { 'COMMAND:LOCATION' } for more specific contexts | ||
| const CONTEXT_BOOSTS: Record<string, Partial<Record<SuggestionCategory, number>>> = { | ||
| 'STATS:BY': { | ||
| [SuggestionCategory.USER_DEFINED_COLUMN]: -300, // From 300 to 0 |
There was a problem hiding this comment.
We have an integration test that does this only inside stats by: select and then double-click arrow down and expect to find create control after add histogram and col0 (🫤) . So I added this ability to do nested context sorting (which is nice anyway)
stratoula
left a comment
There was a problem hiding this comment.
This is a very nice enhancement, I just encountered some bugs and some feedback on the categories names to be easier to understand
src/platform/packages/shared/kbn-esql-ast/src/commands_registry/commands/enrich/util.ts
Outdated
Show resolved
Hide resolved
src/platform/packages/shared/kbn-esql-ast/src/commands_registry/complete_items.ts
Outdated
Show resolved
Hide resolved
| categorizationField?: string; | ||
| }) => { | ||
| const queries = [ | ||
| const queries: QueryTemplate[] = [ |
There was a problem hiding this comment.
These will always be SuggestionCategory.RECOMMENDED_QUERY_SEARCH, why don't you put this in the helpers who give the suggestions?
getRecommendedQueriesTemplatesFromExtensions and getRecommendedQueriesSuggestionsFromStaticTemplates
There was a problem hiding this comment.
but now we depends on Sortext in getRecommendedQueriesSuggestionsFromStaticTemplates. I thought we were going to deprecate it. The old code did sortText: query?.sortText ?? 'E',
sortText: query?.sortText ?? 'E',
category:
query.sortText === 'D'
? SuggestionCategory.RECOMMENDED_QUERY_SEARCH
: SuggestionCategory.RECOMMENDED_QUERY,There was a problem hiding this comment.
Hmmm why do you need to do this?
Maybe I am not following but you have 2 types of queries
- The ones that come from extensions --> getRecommendedQueriesTemplatesFromExtensions
- The static ones --> getRecommendedQueriesSuggestionsFromStaticTemplates
The first have more priority
So apply the category there. why do you need to do this?
query.sortText === 'D'
? SuggestionCategory.RECOMMENDED_QUERY_SEARCH
: SuggestionCategory.RECOMMENDED_QUERY,
src/platform/packages/shared/kbn-esql-ast/src/definitions/utils/functions.ts
Outdated
Show resolved
Hide resolved
src/platform/packages/shared/kbn-esql-ast/src/sorting/priority_provider.ts
Outdated
Show resolved
Hide resolved
src/platform/packages/shared/kbn-esql-ast/src/sorting/priority_provider.ts
Outdated
Show resolved
Hide resolved
src/platform/packages/shared/kbn-esql-ast/src/sorting/suggestion_ordering_engine.ts
Show resolved
Hide resolved
|
@bartoval can we make sure also that the select from the timepicker is second here??
Maybe it is already with your changes I didnt test |
Second place or is first place also okay?
|
Be the first is also ok 🆗 |
stratoula
left a comment
There was a problem hiding this comment.
Looks much better, some small comments but we are very very close!!
| categorizationField?: string; | ||
| }) => { | ||
| const queries = [ | ||
| const queries: QueryTemplate[] = [ |
There was a problem hiding this comment.
Hmmm why do you need to do this?
Maybe I am not following but you have 2 types of queries
- The ones that come from extensions --> getRecommendedQueriesTemplatesFromExtensions
- The static ones --> getRecommendedQueriesSuggestionsFromStaticTemplates
The first have more priority
So apply the category there. why do you need to do this?
query.sortText === 'D'
? SuggestionCategory.RECOMMENDED_QUERY_SEARCH
: SuggestionCategory.RECOMMENDED_QUERY,
| kind: 'Issue', | ||
| detail: query.description, | ||
| sortText: query?.sortText ?? 'E', | ||
| category: |
There was a problem hiding this comment.
I dont get why you have to do this 🤔 Check my other comment
There was a problem hiding this comment.
Are you saying that the category field should not be here or or should not have the logic
query.sortText === 'D' ? SuggestionCategory.RECOMMENDED_QUERY_SEARCH : SuggestionCategory.RECOMMENDED_QUERY,
regarding this last point:
I did a different division. I considered all the queries as RECOMMENDED_QUERY and then just one RECOMMENDED_QUERY_SEARCH. Simply to respect the sort order. sortText: query?.sortText ?? 'E'
There is a query that must be at the top search all fields" suggestions. If it has the same priority as the others, it is sorted alphabetically.
What I don't understand is whether we want to deprecate sortText. If yes I apply another way to do controlled sorts within the same category, otherwise I'll use it.
There was a problem hiding this comment.
ok I think I get it now. What we want is:
I did a different division. I considered all the queries as RECOMMENDED_QUERY and then just one RECOMMENDED_QUERY_SEARCH. Simply to respect the sort order.
Yes I get it, you are prioritizing the search query correctly, so this makes sense to have a different category. Can you just name it RECOMMENDED_QUERY_WITH_PRIORITY to be more generic? We might want to prioritize something else or more in the future
What I don't understand is whether we want to deprecate sortText
Yes we want. I am sorry I got confused I guess. We don't want this
query.sortText === 'D' ? SuggestionCategory.RECOMMENDED_QUERY_SEARCH : SuggestionCategory.RECOMMENDED_QUERY
your previous implementation makes pretty sense now, sorryyyyy
...form/packages/shared/kbn-esql-ast/src/commands_registry/options/recommended_queries/index.ts
Outdated
Show resolved
Hide resolved
...form/packages/shared/kbn-esql-ast/src/commands_registry/options/recommended_queries/index.ts
Outdated
Show resolved
Hide resolved
now an integration test in discover fails. There are tests that expect some suggestion in fixed positions. so I apply the other way ... or I go to change the test |
Change the test! |
1f5ec49 to
9e90fe9
Compare
💔 Build Failed
Failed CI StepsHistory
cc @bartoval |
9e90fe9 to
5708c8c
Compare
stratoula
left a comment
There was a problem hiding this comment.
Yesss! It looks really nice 👏
…astic#243312) **Work in progress** ## Summary elastic#197113 - Add priority rules by new suggestItem prop called category. - rules take precedence and the lowest wins - You can increase or decrease the priority of certain rules on a per-command basis. - the final priority is the base priority + boost commands priority - monaco editor receives a **new sequence of numbers normalized** and based on the priority roles system (no more A, B, 1C..) **Notes:** - We don't currently prioritize commands by preference (I don't know if it's needed, but it's easily extendable in the system) - The system is static for now --------- Co-authored-by: Stratou <efstratia.kalafateli@elastic.co>





Work in progress
Summary
#197113
Notes: