Skip to content

String-Only Suggestions for Like and RLike Operators#244903

Merged
bartoval merged 5 commits intoelastic:mainfrom
bartoval:like_must_suggest_only_strings
Dec 5, 2025
Merged

String-Only Suggestions for Like and RLike Operators#244903
bartoval merged 5 commits intoelastic:mainfrom
bartoval:like_must_suggest_only_strings

Conversation

@bartoval
Copy link
Contributor

@bartoval bartoval commented Dec 2, 2025

Summary

The(Not)Likeand (Not)RLike operators should suggest only Text, because they perform pattern matching. Their suggestion logic can follow the same approach used for Rerank and Completion.
Currently they suggest a bit of everything.

like.mp4
@bartoval bartoval self-assigned this Dec 2, 2025
@bartoval bartoval requested a review from a team as a code owner December 2, 2025 13:26
@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 labels Dec 2, 2025
@elasticmachine
Copy link
Contributor

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

@bartoval bartoval force-pushed the like_must_suggest_only_strings branch from ae81022 to 35ec825 Compare December 2, 2025 15:23
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.

Very nice enhancement, left some comments to improve the suggestions!


/** Returns true if we should suggest opening a list for the right operand */
export function shouldSuggestOpenListForOperand(operand: any): boolean {
export const LIKE_OPERATOR_REGEX = /\b(not\s+)?(r?like)\s*$/i;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that we had it like that but isn't it dangerous to check for the operands with regex in the entire queryString? As we are looking into it in this PR, does it makes sense to check here if we can use AST to detect the operands instead of regexes?

Copy link
Contributor Author

@bartoval bartoval Dec 5, 2025

Choose a reason for hiding this comment

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

Regexes are used to handle unknown cases when these 3 operators are incomplete. However, they are only used to route between "partials" and "non-partials." Afterwards, I either use the ast node if it exists or create a synthetic one.

Operator Outside Function Inside ANY Function Regex Necessary?
IS NULL  Parser ✅ Parser ❌ (unknown) ✅ Yes (for nested)
IS NOT NULL  Parser ✅ Parser ❌ (unknown) ✅ Yes (for nested)
IN  Parser ✅ Parser ❌ (unknown) ✅ Yes (for nested)
NOT IN  Parser ✅ Parser ❌ (unknown) ✅ Yes (for nested)
LIKE/RLIKE  Parser ❌ Parser ❌ (unknown) ✅ Yes (always)
return IS_NULL_OPERATOR_REGEX.test(innerText);
}

export function isOperandMissing(operand: any): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't like anys 😄

// RLIKE: regular expression pattern
const { snippet, label, detail } = isRlike
? { snippet: '"${0:.*}"', label: 'regex', detail: 'Regular expression pattern' }
: { snippet: '"${0:%}"', label: 'pattern', detail: 'Use % for any chars, _ for single char' };
Copy link
Contributor

Choose a reason for hiding this comment

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

@florent-leborgne can you help here with the text too? We want to instruct users to use a pattern for like.

% (Percent)
Matches any sequence of zero or more characters. The most common wildcard for general substring matching.

_ (Underscore)
Matches any single character. Useful for fixed-length patterns or finding variations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above instead of having one suggestion we can have 2, one for _ and one for percent explaining what they do.

// LIKE: wildcard pattern (% = any chars, _ = single char)
// RLIKE: regular expression pattern
const { snippet, label, detail } = isRlike
? { snippet: '"${0:.*}"', label: 'regex', detail: 'Regular expression pattern' }
Copy link
Contributor

Choose a reason for hiding this comment

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

@florent-leborgne can you help here with the text? We want to instruct users to use a pattern for rlike.

Some core features

.* (Any String)
Matches any sequence of zero or more characters.

. (Any Single Char)
Matches any single character.

^ and $ (Anchors)
Force the match to the start (^) or end ($) of the string, which improves performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing we can do for both like and rlike is to have more than one suggestion.

So here:

.* --> Match any sequence of zero or more characters

. --> Match any single character

^ --> ...

$ --> ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Super nice!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/esql-ast 626 628 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 4.1MB 4.1MB +970.0B
Unknown metric groups

API count

id before after diff
@kbn/esql-ast 820 822 +2

History

cc @bartoval

@bartoval bartoval merged commit 30983fc into elastic:main Dec 5, 2025
12 checks passed
wildemat pushed a commit to wildemat/kibana that referenced this pull request Dec 5, 2025
## Summary

The` (Not)Like `and `(Not)RLike` operators should suggest only Text,
because they perform pattern matching. Their suggestion logic can follow
the same approach used for `Rerank `and `Completion`.
Currently they suggest a bit of everything.


https://github.com/user-attachments/assets/6049ff9a-9c4a-43bb-9291-75b4b7635a4f
JordanSh pushed a commit to JordanSh/kibana that referenced this pull request Dec 9, 2025
## Summary

The` (Not)Like `and `(Not)RLike` operators should suggest only Text,
because they perform pattern matching. Their suggestion logic can follow
the same approach used for `Rerank `and `Completion`.
Currently they suggest a bit of everything.


https://github.com/user-attachments/assets/6049ff9a-9c4a-43bb-9291-75b4b7635a4f
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