-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Today, ES|QL offers the STARTS_WITH and ENDS_WITH functions. For example, STARTS_WITH(first_name, "Eric") would match for the value Eric. A so-called "proper prefix" matches if the value starts with the given string but is not equal to it. For example, the proper prefix "Eric" would match for Erica but not for Eric. In regex terms, the difference is between Eric.* (prefix) and Eric.+ (proper prefix).
The use case I have in mind are PromQL queries where regex matching on labels is a common practice. To speed up the regex filters, we're translating regexes starting or ending with .* to STARTS_WITH/ ENDS_WITH functions. We also want to translate proper prefix/suffix regexes (.+), for label selectors like label=~"Eric.+". We can of course translate this into label != "Eric" AND STARTS_WITH(label, "Eric"), but it would be more elegant to have first class support for this. @costin mentioned that this could be a good general addition to ES|QL.
Before starting with the implementation, I wanted to get consensus on whether this is a desirable addition to ES|QL and how the syntax should look like. My suggestion is to add a STARTS_WITH_PROPER/ENDS_WITH_PROPER function, but we could also add an optional parameter to the existing functions, e.g. STARTS_WITH(label, "Eric", true), however that would be less readable in my opinion.