-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Creates ES|QL where filters for ordinal charts #184420
Creates ES|QL where filters for ordinal charts #184420
Conversation
Pinging @elastic/kibana-esql (Team:ESQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana.jsonc
changes LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first review round.
Noticed some possible improvement over the appendWhereClauseToESQLQuery
logic:
-
forced casting fro
ip
field typesfrom kibana_sample_data_logs | stats count() by ip | where ip == "55.237.229.59"
that is a valid ES|QL, but currently what it gets configured is this version:
from kibana_sample_data_logs | stats count() by ip | where `ip`::string=="55.237.229.59"
-
why is it always quoting variable/fields? There's an AST function that can help here, identifying when a variable/field needs to be wrapped.
-
where the filter is triggered by the multi-series tooltip is does not work
- is it a bit annoying that when the
where
clause is added to the query there's the probability that the visualization changes. I see how that would make "more sense" for some data changes, but perhaps the process should include a prompt to "suggest" to the user the new chart type while keeping the previous type?
When in dashboard I've noticed that legend items have the filter popup active. Of course clicking on them doesn't do anything, as the filtering I understand applies only to Discover, right?
This is present also in main
, so it's ok to not specifically fix this here.
src/plugins/data/public/actions/filters/create_filters_from_value_click.ts
Outdated
Show resolved
Hide resolved
@dej611 thanx. My answers to your questions:
When we created the function ip fields needed casting. I want to revisit this function but I am waiting some more cast improvements from the ES team. I would do this on a follow up PR, it is irrelevant with the current, as this functionality already exists in main
Same as above!
We have already an issue for this #184631
True I will create an issue for that
Thanx I will take a look in this PR |
|
@dej611 good catch with the tooltip actions, I disabled it for this PR (I had already done it for XY charts but not for heatmap and partition charts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple of questions on some async code
src/plugins/data/public/actions/filters/create_filters_from_value_click.ts
Outdated
Show resolved
Hide resolved
src/plugins/data/public/actions/filters/create_filters_from_value_click.ts
Outdated
Show resolved
Hide resolved
src/plugins/data/public/actions/filters/create_filters_from_value_click.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm seeing another bug. I'm using this query:
from kibana_sample_data_logs
| stats total_bytes = sum(bytes) by agent
And in the Lens configuration, I'm using agent
as the Breakdown field, and when I click on a bar in the chart, it doesn't filter and I get this error:
create_filters_from_value_click.ts:124 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'meta')
at create_filters_from_value_click.ts:124:1
at Array.filter (<anonymous>)
at appendFilterToESQLQueryFromValueClickAction (create_filters_from_value_click.ts:122:1)
Screen recording:
Screen.Recording.2024-06-06.at.1.53.03.PM.mov
It is due to @dej611 's recommendation. It worked before. I will look into it, thanx |
@lukasolson fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I found another issue, but I think it's an existing bug that just shows up in this PR because clicking on a bar before this PR does nothing.
- Load sample web logs
- Switch to ES|QL and use the following query:
from kibana_sample_data_logs
| stats total_bytes = sum(bytes) by extension, bytes % 5
- Edit the Lens visualization and drag
bytes % 5
to the horizontal axis (notice the x-axis title still says "extension" even after you changed it - Click on a bar in the chart
Instead of filtering on bytes % 5
, it filters on extension
and you get the following error:
[esql] > Unexpected error from Elasticsearch: verification_exception - Found 1 problem
line 3:9: first argument of [`extension`==2] is [text] so second argument must also be [text] but was [integer]
Screen recording:
Untitled.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really awesome! It's great to see this all coming together. Just added a couple of minor nits below. Regarding the other bug, I'm not sure it's something we need to fix in this PR since it's probably an existing bug.
src/plugins/data/public/actions/filters/create_filters_from_value_click.ts
Outdated
Show resolved
Hide resolved
// ES|QL charts have a different way of applying filters, | ||
// they are appending a where clause to the query | ||
const queryString = appendFilterToESQLQueryFromValueClickAction(context.data); | ||
await getStartServices().uiActions.getTrigger('UPDATE_ESQL_QUERY_TRIGGER').exec({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we use a constant (and export it) for 'UPDATE_ESQL_QUERY_TRIGGER'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I didnt do it is because if I export it from the text-based languages plugin (where the trigger is being registered) it will create circular dependencies with the data plugin. I could export it from the esql-utils package but it seems a bit unrelated to me. So I will leave it as it is for now and I will think about it more when another usage will be required.
…lue_click.ts Co-authored-by: Lukas Olson <[email protected]>
@lukasolson thanx, I created a separate issue for the bug here #185636 because the root cause is different. If you remove the columns and add it by clicking the dimension button and filter you get the filter correctly (and the axis(, the drag and drop does something weird here. |
/ci |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Closes #183425
This PR enables the creation of where clause filters by clicking a chart in Discover and wherever the ES|QL editor exists. This means that this is not available in dashboards.
This is possible only for ordinal charts. For date fields is quite difficult to know the interval so I don't allow it for now. We already support brushing so time filtering is already available.
Checklist