Skip to content

[ES|QL] Use correct timeFieldName for time brush filter #221322

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

Merged
merged 8 commits into from
May 26, 2025

Conversation

markov00
Copy link
Member

@markov00 markov00 commented May 22, 2025

Summary

fix #221241

Bug and fix descriptions

The logic that applies a time filter by updating the time picker vs adding it as a filter pill in the filter bar is described here:

const { timeRangeFilter, restOfFilters } = extractTimeFilter(
timeFieldName,
selectedFilters
);
filterManager.addFilters(restOfFilters);
if (timeRangeFilter) {
timeFilter.setTime(convertRangeFilterToTimeRange(timeRangeFilter));
}

The extractTimeFilter function extracts the timeRangeFilter only if the timeFieldName === keys(filter.query.range)[0] . The problem was that the first key of query.range was different than the timeFieldName. That timeFieldName in the ESQL world was wrongly applied via the table.columns[xAxisColumnIndex].name that doesn't reflect the actual column name for ES|QL, in fact that name reflect the visualization label name for the time dimension. In particular, before the fix, that timeFieldName was set as the axis name (e.g.@timestamp every 5 minute ) and cause the time range filter to fail to be extracted from the filters list.

A combination of two PRs caused this to be now anymore the correct behaviour:

Both PR causes the extractTimeFilter to fail to extract the timeFilter, pushing the filter up to the filter pills.

Side notes

This could be probably fixed in other ways, like by avoiding using the sourceField in ESQL, or by using only the column.name in the filter creation, or by avoiding checking the timeFieldName against the query.range key (not really sure why this is required). In general the problem here is that there is a low confidence on what these fields/params are supposed to be and which is supposted to be the identifiers to use everywhere. For example the column ids reflects only a link between the rows and the column descriptions, the name is the associated label, but can we rely on that label for filtering? i believe we need a stronger connection with the data and the actual original source field or column identifier is a better choice.
I believe a valid subsequent task is #189044

@elasticmachine
Copy link
Contributor

elasticmachine commented May 22, 2025

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!

@markov00 markov00 added bug Fixes for quality problems that affect the customer experience Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) Feature:ES|QL ES|QL related features in Kibana backport:version Backport to applied version labels v9.1.0 v8.19.0 release_note:skip Skip the PR/issue when compiling release notes labels May 22, 2025
@markov00 markov00 marked this pull request as ready for review May 26, 2025 07:19
@markov00 markov00 requested review from a team as code owners May 26, 2025 07:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
expressionXY 99.7KB 99.8KB +102.0B

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 3.7MB 3.7MB -50.0B

History

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, @markov00! LGTM 👍

Also noticed that in ES|QL mode clicking on a bucket does not do anything. Is it a separate issue or can they be related?

@markov00
Copy link
Member Author

Also noticed that in ES|QL mode clicking on a bucket does not do anything. Is it a separate issue or can they be related?

Hey @jughosta Clicking on ESQL mode works only if you have a breakdown and you click on one the breakdown category. It doesn't work like the the standard Lens chart if you click on a bucket to filter by that bucket time window.
It doesn't also work in Dashboard (no matter what you click), there is not filter yet there

@markov00 markov00 merged commit eb4ba96 into elastic:main May 26, 2025
11 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15256641822

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request May 26, 2025
## Summary

fix elastic#221241

## Bug and fix descriptions

The logic that applies a time filter by updating the time picker vs
adding it as a filter pill in the filter bar is described here:

https://github.com/elastic/kibana/blob/e877bafa3e4725d3e7cfd3b2ca0be4bc6d88a0b9/src/platform/plugins/shared/unified_search/public/actions/apply_filter_action/apply_filter_action.tsx#L107-L114

The `extractTimeFilter` function extracts the `timeRangeFilter` only if
the `timeFieldName === keys(filter.query.range)[0]` . The problem was
that the first key of `query.range` was different than the
`timeFieldName`. That `timeFieldName` in the ESQL world was wrongly
applied via the ` table.columns[xAxisColumnIndex].name` that doesn't
reflect the actual column name for ES|QL, in fact that name reflect the
visualization label name for the time dimension. In particular, before
the fix, that timeFieldName was set as the axis name (e.g.`@timestamp
every 5 minute` ) and cause the time range filter to fail to be
extracted from the filters list.

A combination of two PRs caused this to be now anymore the correct
behaviour:
- this PR elastic#196049 introduced the
use of the `souceField` as field name for the creation of filter from a
range
- this PR elastic#217719 instead
introduced the use of `sourceField` also for ESQL datasources. This
field points to the actual column name described in the ESQL query.

Both PR causes the `extractTimeFilter` to fail to extract the
timeFilter, pushing the filter up to the filter pills.

### Side notes

This could be probably fixed in other ways, like by avoiding using the
`sourceField` in ESQL, or by using only the column.name in the filter
creation, or by avoiding checking the `timeFieldName` against the
`query.range` key (not really sure why this is required). In general the
problem here is that there is a low confidence on what these
fields/params are supposed to be and which is supposted to be the
identifiers to use everywhere. For example the column ids reflects only
a link between the rows and the column descriptions, the name is the
associated label, but can we rely on that label for filtering? i believe
we need a stronger connection with the data and the actual original
source field or column identifier is a better choice.
I believe a valid subsequent task is
elastic#189044

(cherry picked from commit eb4ba96)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request May 26, 2025
…) (#221524)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[ES|QL] Use correct timeFieldName for time brush filter
(#221322)](#221322)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Marco
Vettorello","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-26T14:41:06Z","message":"[ES|QL]
Use correct timeFieldName for time brush filter (#221322)\n\n##
Summary\n\nfix #221241\n\n## Bug and fix descriptions\n\nThe logic that
applies a time filter by updating the time picker vs\nadding it as a
filter pill in the filter bar is described
here:\n\nhttps://github.com/elastic/kibana/blob/e877bafa3e4725d3e7cfd3b2ca0be4bc6d88a0b9/src/platform/plugins/shared/unified_search/public/actions/apply_filter_action/apply_filter_action.tsx#L107-L114\n\nThe
`extractTimeFilter` function extracts the `timeRangeFilter` only if\nthe
`timeFieldName === keys(filter.query.range)[0]` . The problem was\nthat
the first key of `query.range` was different than the\n`timeFieldName`.
That `timeFieldName` in the ESQL world was wrongly\napplied via the `
table.columns[xAxisColumnIndex].name` that doesn't\nreflect the actual
column name for ES|QL, in fact that name reflect the\nvisualization
label name for the time dimension. In particular, before\nthe fix, that
timeFieldName was set as the axis name (e.g.`@timestamp\nevery 5 minute`
) and cause the time range filter to fail to be\nextracted from the
filters list.\n\nA combination of two PRs caused this to be now anymore
the correct\nbehaviour:\n- this PR
#196049 introduced the\nuse of the
`souceField` as field name for the creation of filter from a\nrange\n-
this PR #217719
instead\nintroduced the use of `sourceField` also for ESQL datasources.
This\nfield points to the actual column name described in the ESQL
query.\n\nBoth PR causes the `extractTimeFilter` to fail to extract
the\ntimeFilter, pushing the filter up to the filter pills.\n\n### Side
notes\n\nThis could be probably fixed in other ways, like by avoiding
using the\n`sourceField` in ESQL, or by using only the column.name in
the filter\ncreation, or by avoiding checking the `timeFieldName`
against the\n`query.range` key (not really sure why this is required).
In general the\nproblem here is that there is a low confidence on what
these\nfields/params are supposed to be and which is supposted to be
the\nidentifiers to use everywhere. For example the column ids reflects
only\na link between the rows and the column descriptions, the name is
the\nassociated label, but can we rely on that label for filtering? i
believe\nwe need a stronger connection with the data and the actual
original\nsource field or column identifier is a better choice.\nI
believe a valid subsequent task
is\nhttps://github.com//issues/189044","sha":"eb4ba962ec29256f086ade49d04150c3aec1789b","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Visualizations","release_note:skip","Feature:ES|QL","backport:version","v9.1.0","v8.19.0"],"title":"[ES|QL]
Use correct timeFieldName for time brush
filter","number":221322,"url":"https://github.com/elastic/kibana/pull/221322","mergeCommit":{"message":"[ES|QL]
Use correct timeFieldName for time brush filter (#221322)\n\n##
Summary\n\nfix #221241\n\n## Bug and fix descriptions\n\nThe logic that
applies a time filter by updating the time picker vs\nadding it as a
filter pill in the filter bar is described
here:\n\nhttps://github.com/elastic/kibana/blob/e877bafa3e4725d3e7cfd3b2ca0be4bc6d88a0b9/src/platform/plugins/shared/unified_search/public/actions/apply_filter_action/apply_filter_action.tsx#L107-L114\n\nThe
`extractTimeFilter` function extracts the `timeRangeFilter` only if\nthe
`timeFieldName === keys(filter.query.range)[0]` . The problem was\nthat
the first key of `query.range` was different than the\n`timeFieldName`.
That `timeFieldName` in the ESQL world was wrongly\napplied via the `
table.columns[xAxisColumnIndex].name` that doesn't\nreflect the actual
column name for ES|QL, in fact that name reflect the\nvisualization
label name for the time dimension. In particular, before\nthe fix, that
timeFieldName was set as the axis name (e.g.`@timestamp\nevery 5 minute`
) and cause the time range filter to fail to be\nextracted from the
filters list.\n\nA combination of two PRs caused this to be now anymore
the correct\nbehaviour:\n- this PR
#196049 introduced the\nuse of the
`souceField` as field name for the creation of filter from a\nrange\n-
this PR #217719
instead\nintroduced the use of `sourceField` also for ESQL datasources.
This\nfield points to the actual column name described in the ESQL
query.\n\nBoth PR causes the `extractTimeFilter` to fail to extract
the\ntimeFilter, pushing the filter up to the filter pills.\n\n### Side
notes\n\nThis could be probably fixed in other ways, like by avoiding
using the\n`sourceField` in ESQL, or by using only the column.name in
the filter\ncreation, or by avoiding checking the `timeFieldName`
against the\n`query.range` key (not really sure why this is required).
In general the\nproblem here is that there is a low confidence on what
these\nfields/params are supposed to be and which is supposted to be
the\nidentifiers to use everywhere. For example the column ids reflects
only\na link between the rows and the column descriptions, the name is
the\nassociated label, but can we rely on that label for filtering? i
believe\nwe need a stronger connection with the data and the actual
original\nsource field or column identifier is a better choice.\nI
believe a valid subsequent task
is\nhttps://github.com//issues/189044","sha":"eb4ba962ec29256f086ade49d04150c3aec1789b"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221322","number":221322,"mergeCommit":{"message":"[ES|QL]
Use correct timeFieldName for time brush filter (#221322)\n\n##
Summary\n\nfix #221241\n\n## Bug and fix descriptions\n\nThe logic that
applies a time filter by updating the time picker vs\nadding it as a
filter pill in the filter bar is described
here:\n\nhttps://github.com/elastic/kibana/blob/e877bafa3e4725d3e7cfd3b2ca0be4bc6d88a0b9/src/platform/plugins/shared/unified_search/public/actions/apply_filter_action/apply_filter_action.tsx#L107-L114\n\nThe
`extractTimeFilter` function extracts the `timeRangeFilter` only if\nthe
`timeFieldName === keys(filter.query.range)[0]` . The problem was\nthat
the first key of `query.range` was different than the\n`timeFieldName`.
That `timeFieldName` in the ESQL world was wrongly\napplied via the `
table.columns[xAxisColumnIndex].name` that doesn't\nreflect the actual
column name for ES|QL, in fact that name reflect the\nvisualization
label name for the time dimension. In particular, before\nthe fix, that
timeFieldName was set as the axis name (e.g.`@timestamp\nevery 5 minute`
) and cause the time range filter to fail to be\nextracted from the
filters list.\n\nA combination of two PRs caused this to be now anymore
the correct\nbehaviour:\n- this PR
#196049 introduced the\nuse of the
`souceField` as field name for the creation of filter from a\nrange\n-
this PR #217719
instead\nintroduced the use of `sourceField` also for ESQL datasources.
This\nfield points to the actual column name described in the ESQL
query.\n\nBoth PR causes the `extractTimeFilter` to fail to extract
the\ntimeFilter, pushing the filter up to the filter pills.\n\n### Side
notes\n\nThis could be probably fixed in other ways, like by avoiding
using the\n`sourceField` in ESQL, or by using only the column.name in
the filter\ncreation, or by avoiding checking the `timeFieldName`
against the\n`query.range` key (not really sure why this is required).
In general the\nproblem here is that there is a low confidence on what
these\nfields/params are supposed to be and which is supposted to be
the\nidentifiers to use everywhere. For example the column ids reflects
only\na link between the rows and the column descriptions, the name is
the\nassociated label, but can we rely on that label for filtering? i
believe\nwe need a stronger connection with the data and the actual
original\nsource field or column identifier is a better choice.\nI
believe a valid subsequent task
is\nhttps://github.com//issues/189044","sha":"eb4ba962ec29256f086ade49d04150c3aec1789b"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Marco Vettorello <[email protected]>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
## Summary

fix elastic#221241

## Bug and fix descriptions

The logic that applies a time filter by updating the time picker vs
adding it as a filter pill in the filter bar is described here:

https://github.com/elastic/kibana/blob/e877bafa3e4725d3e7cfd3b2ca0be4bc6d88a0b9/src/platform/plugins/shared/unified_search/public/actions/apply_filter_action/apply_filter_action.tsx#L107-L114

The `extractTimeFilter` function extracts the `timeRangeFilter` only if
the `timeFieldName === keys(filter.query.range)[0]` . The problem was
that the first key of `query.range` was different than the
`timeFieldName`. That `timeFieldName` in the ESQL world was wrongly
applied via the ` table.columns[xAxisColumnIndex].name` that doesn't
reflect the actual column name for ES|QL, in fact that name reflect the
visualization label name for the time dimension. In particular, before
the fix, that timeFieldName was set as the axis name (e.g.`@timestamp
every 5 minute` ) and cause the time range filter to fail to be
extracted from the filters list.

A combination of two PRs caused this to be now anymore the correct
behaviour:
- this PR elastic#196049 introduced the
use of the `souceField` as field name for the creation of filter from a
range
- this PR elastic#217719 instead
introduced the use of `sourceField` also for ESQL datasources. This
field points to the actual column name described in the ESQL query.

Both PR causes the `extractTimeFilter` to fail to extract the
timeFilter, pushing the filter up to the filter pills.

### Side notes

This could be probably fixed in other ways, like by avoiding using the
`sourceField` in ESQL, or by using only the column.name in the filter
creation, or by avoiding checking the `timeFieldName` against the
`query.range` key (not really sure why this is required). In general the
problem here is that there is a low confidence on what these
fields/params are supposed to be and which is supposted to be the
identifiers to use everywhere. For example the column ids reflects only
a link between the rows and the column descriptions, the name is the
associated label, but can we rely on that label for filtering? i believe
we need a stronger connection with the data and the actual original
source field or column identifier is a better choice.
I believe a valid subsequent task is
elastic#189044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels bug Fixes for quality problems that affect the customer experience Feature:ES|QL ES|QL related features in Kibana release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] [Discover] Filter pills shows up when selecting on the histogram in Discover, and they should not
5 participants