Skip to content
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

[Lens] Global filter for formula #103246

Closed
flash1293 opened this issue Jun 24, 2021 · 3 comments · Fixed by #121768
Closed

[Lens] Global filter for formula #103246

flash1293 opened this issue Jun 24, 2021 · 3 comments · Fixed by #121768
Assignees
Labels
enhancement New value added to drive a business result Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@flash1293
Copy link
Contributor

Right now it's not possible to specify a filter on a whole formula dimension like it's possible for regular operations.

This is not limiting functionality because it possible to define a filter per metric within the formula, e.g. count(kql="fieldA: 123"). However there are some common use cases which require multiple metrics using the same filter in all places which quickly becomes annoying because it requires the user to type the same filter multiple times (like percentage of total):
count(kql='my_complex_filter: 123 AND field2 < 34.2') / overall_sum(count(kql='my_complex_filter: 123 AND field2 < 34.2'))

For these cases it would be beneficial to be able to define a filter on the formula itself which is merged into all filters defined per metric used in the formula:

  • User creates new formula
  • User types count() / overall_sum(count())
  • User adds filter via advanced options once: my_complex_filter: 123 AND field2 < 34.2
  • Filter is applied to both count metrics within the formula - equivalent to count(kql='my_complex_filter: 123 AND field2 < 34.2') / overall_sum(count(kql='my_complex_filter: 123 AND field2 < 34.2'))

This gets more complex in case of filters defined in the formula:

  • User creates new formula
  • User types count(kql='fieldA > 12') / count()
  • User adds filter via advanced options: fieldB: "ABC"
  • Filters are merged for each metric - equivalent to count(kql='fieldB: "ABC" AND fieldA > 12') / count(kql='fieldB: "ABC"')

If all queries are defined as kql or all queries are defined as lucene, they can be merged in a very simple way: (${query1}) AND (${query2})

There is one case where this wouldn't work as straightforward - if lucene and KQL queries are mixed this way. There are two ways how this case could be treated:

  • Show error message and don't allow this case
  • compile both queries to query dsl and merge them there

IMHO we should show an error message for the case - it introduces additional complexity and I think this case is extremely rare in practice.

@flash1293 flash1293 added enhancement New value added to drive a business result Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens labels Jun 24, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@dminovski0
Copy link

Can variables be added to the Formula? For example:
let custom_filter = 'my_complex_filter: 123 AND field2 < 34.2'
count(custom_filter) / overall_sum(count(custom_filter)
Or
count(kql=custom_filter) / overall_sum(count(kql=custom_filter))
Perhaps they can define the variables' names in a GUI like in the TSVB bucket script too.

@dej611
Copy link
Contributor

dej611 commented Nov 26, 2021

@dminovski0 variables/references in formula can be tracked here: #94608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants