Skip to content

Conversation

ivancea
Copy link
Contributor

@ivancea ivancea commented Sep 19, 2025

Fixes #135042

This PR:

  • Fixes the get-result not always returning the expected headers
  • Fixes the non-async query incorrectly returning the "is running" async header

@ivancea ivancea requested a review from dnhatn September 19, 2025 11:42
@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v9.2.0 v8.19.5 v9.1.5 v8.18.8 v9.0.8 labels Sep 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @ivancea, I've created a changelog YAML for you.

Comment on lines 210 to +211
public boolean isAsync() {
return isRunning;
return isAsync;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was only being used on a test, so changing it is safe

@ivancea ivancea marked this pull request as ready for review September 19, 2025 13:44
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@ivancea ivancea changed the title ESQL: Fix async get results with inconsistent headers ESQL: Fix async query inconsistent headers Sep 19, 2025
* </p>
*/
static <R> ActionListener<R> unwrapListener(ActionListener<R> listener) {
ActionListener<EsqlQueryResponse> unwrapListener(String asyncExecutionId, ActionListener<EsqlQueryResponse> listener) {
Copy link
Contributor Author

@ivancea ivancea Sep 22, 2025

Choose a reason for hiding this comment

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

I could rename this method, listening to better names here. I was unironically considering switching it to "wrapListener()"

*/
ASYNC_QUERY_STATUS_HEADERS,

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the ASYNC_QUERY_STATUS_HEADERS capability anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless in snapshot or some other special cases, we usually don't remove them.
Also, a 8.19 server could be executing tests against this one (rest compatibility tests), and this one should say "Yes, I can handle that".

if (response.isAsync()) {
if (response.asyncExecutionId().isPresent()) {
String asyncExecutionId = response.asyncExecutionId().get();
threadPool.getThreadContext().addResponseHeader(AsyncExecutionId.ASYNC_EXECUTION_ID_HEADER, asyncExecutionId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Dummy question: why do we need this duplicated (in TransportEsqlAsyncGetResultsAction.java also)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Async queries have 2 endpoints: POST _query/async to execute the query, and GET _query/async/<id>.

The bug was that we already had the headers for query execution (Here I just refactored it a bit), but the "get" class wasn't setting them.

It worked when the GET returned a result, as the headers are stored with it. But before it had the result, there were no headers.

Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks Ivan!

@ivancea ivancea merged commit 8e4f8f3 into elastic:main Sep 23, 2025
34 checks passed
@ivancea ivancea deleted the esql-async-headers-fix branch September 23, 2025 10:16
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts
9.1 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts
9.0 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 135078

ivancea added a commit to ivancea/elasticsearch that referenced this pull request Sep 23, 2025
Fixes elastic#135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header
ivancea added a commit to ivancea/elasticsearch that referenced this pull request Sep 23, 2025
Fixes elastic#135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header
ivancea added a commit to ivancea/elasticsearch that referenced this pull request Sep 23, 2025
Fixes elastic#135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header
ivancea added a commit that referenced this pull request Sep 29, 2025
* ESQL: Fix async query inconsistent headers (#135078)

Fixes #135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header

* Restore some wrongly backported tests
ivancea added a commit that referenced this pull request Sep 29, 2025
Fixes #135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header
elasticsearchmachine pushed a commit that referenced this pull request Sep 29, 2025
Fixes #135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header
elasticsearchmachine pushed a commit that referenced this pull request Sep 30, 2025
* ESQL: Fix async query inconsistent headers (#135078)

Fixes #135042

This PR:
- Fixes the get-result not always returning the expected headers
- Fixes the non-async query incorrectly returning the "is running" async header

* Revert rest tests file

* Added main changes on test class

* Backported test for the headers fix

* Remove unrelated changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.18.8 v8.19.5 v9.0.8 v9.1.5 v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ES|QL GET _query/async/{id} returns inconsistent headers
4 participants