-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KQL] Generate expression string from AST node #77971
Comments
Pinging @elastic/kibana-app-arch (Team:AppArch) |
Revisiting this issue and the ML team thinks that we should escalate the impact level to something higher. As integration between different teams increases, having a one source of truth to build and generate the query expressions will provide better consistency, reduce brittle code (e.g. regex expressions 👀 ), and lead to less potential bugs. |
Could you point me to that code as an example please? |
Hi @Dosant, an example of is in Machine Learning's Anomaly detection/alerts where we allow users to add custom url templates to different parts of Kibana (like Discover, Dashboard, Metrics, APM, etc.) I also want to clarify that this chunk of code was written a long time ago, so perhaps there are already better mechanisms in place to help achieve this functionality. The url template looks something like:
Which we then substitute the tokens like So just one use case but I bet there are other solutions who might benefit from the ability to build expressions from the nodes. |
cc @vadimkibana i think for bulding custom url templates to different parts of kibana url locators should be used |
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
## Summary Resolves #77971. Adds a `toKqlExpression` method to the `@kbn/es-query` that allows generating a KQL expression from an AST node. Example: ```ts const node = fromKueryExpression('extension: "jpg"'); const kql = toKqlExpression(node); // 'extension: "jpg"' ``` Note that the generated KQL expression may not exactly match the original text (whitespace is not preserved, parentheses may be added, etc.). ### Checklist Delete any items that are not applicable to this PR. - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
many thanks @lukasolson 🎉 |
Describe the feature:
The
@kbn/es-query
KQL utilities currently exports these methods:fromKueryExpression
: Receives a KQL expression and returns the generated KQL AST.toElasticsearchQuery
: Receives KQL AST and returns the generated Elasticsearch query.There is no current utility for taking KQL AST and generating the KQL expression (
toKueryExpression
).Describe a specific use case for the feature:
In the ML plugin, we allow users to link anomaly records with the other Kibana pages by configuring custom URLs. Most of those URLs contain a
kuery
string to populate a KQL bar with a query on the target page. At the moment we parse a URL template, replace tokens with values from the anomaly record and generate a result query using regular expressions. With all possible special characters and escaping rules, the current solution has potential issues. AdjustingKueryNode
and receiving a result kuery expression seems like a more robust solution in this case.The text was updated successfully, but these errors were encountered: