Skip to content

Comments

[UnifiedSearch][ESQL] Fix edited query overwriting when a request is finished#224671

Merged
kertal merged 14 commits intoelastic:mainfrom
kertal:unified-search-prevent-esql-edit-overwrite
Jul 3, 2025
Merged

[UnifiedSearch][ESQL] Fix edited query overwriting when a request is finished#224671
kertal merged 14 commits intoelastic:mainfrom
kertal:unified-search-prevent-esql-edit-overwrite

Conversation

@kertal
Copy link
Member

@kertal kertal commented Jun 20, 2025

Summary

Resolves #192950

When changing the ESQL query while the request is still running, the changes were overwritten once the currently running request resolved. This PR fixes this behavior in UnifiedSearch by aligning to the way KQL works

How to test:

  1. Go to Discover in ESQL mode, in DevTools slow the network to 3G, or use a long running query
  2. Run query
  3. While query is running, change the query in the ESQL editor
  4. When the query returns result, the ESQL editor value is no longer set to the original value
  5. Given you slowed the network, unslow it, or submit "praises" to the network how slow it is today! 🤬

Note: I tried to cover this change with a unit test, but it didn't work, in several attempts, also the robot 🤖 was not helpful. Open for ideas (refactoring the change to a pure function would be doable, wanted to keep the scope of this fix small). So manually testing is the only way currently.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

@kertal
Copy link
Member Author

kertal commented Jun 20, 2025

/ci

@kertal
Copy link
Member Author

kertal commented Jun 20, 2025

/ci

}
savedQuery={savedQuery}
onQuerySubmit={defaultOnQuerySubmit(props, data.query, query)}
onQueryChange={props.onQueryChange}
Copy link
Member Author

Choose a reason for hiding this comment

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

During my investigation I figured to, which onQueryChange is in the searcher props, we don't use it under the hood. seems we have no consumer for this, but we might need it in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm always a little skeptical about changing such brittle and widely consumed code... I also don't get any results when checking for references, but that seemed to be the case for all props in SearchBarOwnProps that I checked, so something odd is going on. Just not sure if we should be worried about any odd side effects here since I'm unfamiliar with the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can definitely remove that, to keep it focused, from my perspective. it's not in use, and if it was used, it would not work, when in doubt, let's remove it, and fix it when we need it 👍 wdyt dear @elastic/kibana-presentation

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have any more context at the moment, as we haven't had the bandwidth to really take ownership of this plugin quite yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed it for now, let's add it when we need it 👍

} else if (
nextProps.query &&
isOfAggregateQueryType(nextProps.query) &&
nextProps.query.esql !== get(prevState, 'currentProps.query.esql')
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the main change, we mimic what KQL does. before this change, for ESQL the query was overwritten every time, since it was not checked if the new props value differs from the old one. Now this works.

I tried to cover this change with a unit test, but I couldn't make it work. Since on re-render the currentProps.query.esql, was not kept. This made the unit test pointless 🤷

I mean, we could refactor this part to a unit test, to a pure function. Open to apply this change if valued reviewers want to have it. Or have other ideas

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not overly worried about it tbh, but I wonder if it's possible to test the rendered output in an RTL test? I might not understand exactly what was making it hard to test though. Otherwise a separate function like you mentioned would work if you're feeling proactive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I wanted to do this, I've tried and it didn't work, it might be me of course

Copy link
Member Author

Choose a reason for hiding this comment

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

I've found a way to cover this in a simple way

32cc820

first test fails when I remove the fix

@kertal kertal self-assigned this Jun 23, 2025
@kertal kertal added release_note:fix Feature:Unified search Unified search related tasks Feature:Discover Discover Application Team:ESQL ES|QL related features in Kibana t// Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// labels Jun 23, 2025
@kertal kertal requested a review from a team June 23, 2025 05:59
@kertal kertal changed the title Fix query handling in SearchBarUI for aggregate query type changes [Discover][ESQL] Fix query handling in SearchBarUI for aggregate query type changes Jun 23, 2025
@kertal kertal requested a review from stratoula June 23, 2025 06:00
@kertal kertal marked this pull request as ready for review June 23, 2025 06:00
@kertal kertal requested a review from a team as a code owner June 23, 2025 06:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with the Unified Search code, but from what I can tell it LGTM and definitely fixes the issue in Discover 👍 Thanks for such a thorough investigation and getting to the bottom of this! Glad we didn't need to resort to any hacky workarounds in Discover 🙏

On a side note, maybe you're aware already, but a good approach for testing these types of changes is to use the ES|QL DELAY function like this:

FROM kibana_sample_data_logs | EVAL delay = DELAY(1000ms) | LIMIT 10

} else if (
nextProps.query &&
isOfAggregateQueryType(nextProps.query) &&
nextProps.query.esql !== get(prevState, 'currentProps.query.esql')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not overly worried about it tbh, but I wonder if it's possible to test the rendered output in an RTL test? I might not understand exactly what was making it hard to test though. Otherwise a separate function like you mentioned would work if you're feeling proactive.

}
savedQuery={savedQuery}
onQuerySubmit={defaultOnQuerySubmit(props, data.query, query)}
onQueryChange={props.onQueryChange}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm always a little skeptical about changing such brittle and widely consumed code... I also don't get any results when checking for references, but that seemed to be the case for all props in SearchBarOwnProps that I checked, so something odd is going on. Just not sure if we should be worried about any odd side effects here since I'm unfamiliar with the code.

@kertal kertal enabled auto-merge (squash) July 3, 2025 06:25
@kertal kertal merged commit ca7b021 into elastic:main Jul 3, 2025
11 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.18, 8.19

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

@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
unifiedSearch 336.1KB 336.1KB +63.0B

History

cc @kertal

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 3, 2025
…finished (elastic#224671)

Resolved overwriting changes to the query in the ESQL Editor in UnifiedSearch while the request is still running when the previous request finished

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

💔 Some backports could not be created

Status Branch Result
8.17 Backport failed because of merge conflicts
8.18 Backport failed because of merge conflicts
8.19

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 224671

Questions ?

Please refer to the Backport tool documentation

@stratoula
Copy link
Contributor

@kertal I dont think we need to backport it in v8.18

v8.19, v9.1 and main are enough.

@kertal
Copy link
Member Author

kertal commented Jul 3, 2025

you're right, thx!

@kertal kertal added backport:version Backport to applied version labels v9.1.0 v8.19.0 and removed backport:prev-major labels Jul 3, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.1

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

@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19, 9.1

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 3, 2025
…finished (elastic#224671)

Resolved overwriting changes to the query in the ESQL Editor in UnifiedSearch while the request is still running when the previous request finished

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

💚 All backports created successfully

Status Branch Result
9.1

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 3, 2025
…finished (elastic#224671)

Resolved overwriting changes to the query in the ESQL Editor in UnifiedSearch while the request is still running when the previous request finished

(cherry picked from commit ca7b021)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 3, 2025
…finished (elastic#224671)

Resolved overwriting changes to the query in the ESQL Editor in UnifiedSearch while the request is still running when the previous request finished

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

💚 All backports created successfully

Status Branch Result
8.19
9.1

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 Jul 3, 2025
…est is finished (#224671) (#226344)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[UnifiedSearch][ESQL] Fix edited query overwriting when a request is
finished (#224671)](#224671)

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

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

<!--BACKPORT [{"author":{"name":"Matthias
Wilhelm","email":"matthias.wilhelm@elastic.co"},"sourceCommit":{"committedDate":"2025-07-03T08:14:41Z","message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","Feature:Unified
search","backport:prev-major","Team:ESQL","v9.2.0"],"title":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is
finished","number":224671,"url":"https://github.com/elastic/kibana/pull/224671","mergeCommit":{"message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224671","number":224671,"mergeCommit":{"message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338"}}]}]
BACKPORT-->

Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
kibanamachine added a commit that referenced this pull request Jul 3, 2025
…st is finished (#224671) (#226355)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[UnifiedSearch][ESQL] Fix edited query overwriting when a request is
finished (#224671)](#224671)

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

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

<!--BACKPORT [{"author":{"name":"Matthias
Wilhelm","email":"matthias.wilhelm@elastic.co"},"sourceCommit":{"committedDate":"2025-07-03T08:14:41Z","message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","Feature:Unified
search","Team:ESQL","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is
finished","number":224671,"url":"https://github.com/elastic/kibana/pull/224671","mergeCommit":{"message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338"}},"sourceBranch":"main","suggestedTargetBranches":["9.1"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/226344","number":226344,"state":"OPEN"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224671","number":224671,"mergeCommit":{"message":"[UnifiedSearch][ESQL]
Fix edited query overwriting when a request is finished
(#224671)\n\nResolved overwriting changes to the query in the ESQL
Editor in UnifiedSearch while the request is still running when the
previous request
finished","sha":"ca7b021814e3606434934c9dac0b1be8fbed4338"}}]}]
BACKPORT-->

Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
@kertal kertal deleted the unified-search-prevent-esql-edit-overwrite branch July 6, 2025 07:35
kertal added a commit to kertal/kibana that referenced this pull request Jul 25, 2025
…finished (elastic#224671)

Resolved overwriting changes to the query in the ESQL Editor in UnifiedSearch while the request is still running when the previous request finished
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 Feature:Discover Discover Application Feature:Unified search Unified search related tasks release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// Team:ESQL ES|QL related features in Kibana t// v8.19.0 v9.1.0 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESQL Editor: Query gets overwritten when changed while loading

6 participants