Skip to content

[ES|QL] Add context-aware suggestion ordering with categorization#243312

Merged
bartoval merged 12 commits intoelastic:mainfrom
bartoval:strong_suggestions_priority
Nov 25, 2025
Merged

[ES|QL] Add context-aware suggestion ordering with categorization#243312
bartoval merged 12 commits intoelastic:mainfrom
bartoval:strong_suggestions_priority

Conversation

@bartoval
Copy link
Contributor

@bartoval bartoval commented Nov 18, 2025

Work in progress

Summary

#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
@bartoval bartoval self-assigned this Nov 18, 2025
@bartoval bartoval requested a review from a team as a code owner November 18, 2025 08:42
@bartoval bartoval marked this pull request as draft November 18, 2025 08:42
@bartoval bartoval added the WIP Work in progress label Nov 18, 2025
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import {
Copy link
Contributor Author

@bartoval bartoval Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure we want this level of granularity for operators

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just examples to show how to change priorities per command

@bartoval bartoval force-pushed the strong_suggestions_priority branch 5 times, most recently from 7eb7f7b to 3dae845 Compare November 19, 2025 18:49
@bartoval bartoval force-pushed the strong_suggestions_priority branch 4 times, most recently from 768af6f to f0732b3 Compare November 20, 2025 00:20
@bartoval bartoval force-pushed the strong_suggestions_priority branch from f0732b3 to 2475929 Compare November 20, 2025 07:52
@bartoval bartoval changed the title [ES|QL] Add context-aware suggestion ordering with categorization (WIP) Nov 20, 2025
@bartoval bartoval added release_note:enhancement backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// v9.3.0 and removed WIP Work in progress labels Nov 20, 2025
@bartoval bartoval marked this pull request as ready for review November 20, 2025 07:59
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

@bartoval bartoval force-pushed the strong_suggestions_priority branch from 124ff5e to 9f81fb4 Compare November 20, 2025 08:05
@stratoula
Copy link
Contributor

@bartoval can you use enum for the categories and reuse it everywhere?

@bartoval bartoval force-pushed the strong_suggestions_priority branch from 4059e13 to e6dec13 Compare November 20, 2025 14:31
@bartoval
Copy link
Contributor Author

@bartoval can you use enum for the categories and reuse it everywhere?

e6dec13

@bartoval bartoval force-pushed the strong_suggestions_priority branch from e6dec13 to 75a9ad2 Compare November 20, 2025 20:09
// 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
Copy link
Contributor Author

@bartoval bartoval Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice enhancement, I just encountered some bugs and some feedback on the categories names to be easier to understand

categorizationField?: string;
}) => {
const queries = [
const queries: QueryTemplate[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will always be SuggestionCategory.RECOMMENDED_QUERY_SEARCH, why don't you put this in the helpers who give the suggestions?

getRecommendedQueriesTemplatesFromExtensions and getRecommendedQueriesSuggestionsFromStaticTemplates

Copy link
Contributor Author

@bartoval bartoval Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm why do you need to do this?

Maybe I am not following but you have 2 types of queries

  1. The ones that come from extensions --> getRecommendedQueriesTemplatesFromExtensions
  2. 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aggregations have the highest priority in STATS, this should not change

image

Also in TS we want to prioritize the timeseries_aggs

image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first has been fixed but not the second
image

@bartoval bartoval requested a review from stratoula November 24, 2025 06:43
@stratoula
Copy link
Contributor

@bartoval can we make sure also that the select from the timepicker is second here??

image

Maybe it is already with your changes I didnt test

@bartoval
Copy link
Contributor Author

bartoval commented Nov 24, 2025

@bartoval can we make sure also that the select from the timepicker is second here??

image Maybe it is already with your changes I didnt test

Second place or is first place also okay?

  1. If I move "choose from the time picker" to the CUSTOM ACTION group (same as create control), it will appear as the first item (alphabetical order with the same priority).
  2. Otherwise I create a new CUSTOM_TIME_ACTION group and make it appear as the second.
@stratoula
Copy link
Contributor

Second place or is first place also okay?

  1. If I move "choose from the time picker" to the CUSTOM ACTION group (same as create control), it will appear as the first item (alphabetical order with the same priority).
  2. Otherwise I create a new CUSTOM_TIME_ACTION group and make it appear as the second.

Be the first is also ok 🆗

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better, some small comments but we are very very close!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first has been fixed but not the second
image

categorizationField?: string;
}) => {
const queries = [
const queries: QueryTemplate[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm why do you need to do this?

Maybe I am not following but you have 2 types of queries

  1. The ones that come from extensions --> getRecommendedQueriesTemplatesFromExtensions
  2. 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont get why you have to do this 🤔 Check my other comment

Copy link
Contributor Author

@bartoval bartoval Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@stratoula stratoula Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bartoval
Copy link
Contributor Author

bartoval commented Nov 24, 2025

Looks much better, some small comments but we are very very close!!

Second place or is first place also okay?

  1. If I move "choose from the time picker" to the CUSTOM ACTION group (same as create control), it will appear as the first item (alphabetical order with the same priority).
  2. Otherwise I create a new CUSTOM_TIME_ACTION group and make it appear as the second.

Be the first is also ok 🆗

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

@stratoula
Copy link
Contributor

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!

@bartoval bartoval force-pushed the strong_suggestions_priority branch from 1f5ec49 to 9e90fe9 Compare November 24, 2025 13:38
@elasticmachine
Copy link
Contributor

elasticmachine commented Nov 24, 2025

💔 Build Failed

Failed CI Steps

History

cc @bartoval

@bartoval bartoval force-pushed the strong_suggestions_priority branch from 9e90fe9 to 5708c8c Compare November 24, 2025 14:54
Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesss! It looks really nice 👏

@bartoval bartoval merged commit 2f93b87 into elastic:main Nov 25, 2025
12 checks passed
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Dec 2, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v9.3.0

3 participants