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

Unnecessary multiple requests with the same esagg query #182919

Closed
ppisljar opened this issue May 8, 2024 · 1 comment · Fixed by #182917
Closed

Unnecessary multiple requests with the same esagg query #182919

ppisljar opened this issue May 8, 2024 · 1 comment · Fixed by #182917
Labels
Feature:Search Querying infrastructure in Kibana Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@ppisljar
Copy link
Member

ppisljar commented May 8, 2024

Unnecessary multiple requests with the same esagg query

When a search is sent to ES and a response is received, the search service is looking if the request needs a post-flight request.

if (!this.hasPostFlightRequests()) {
obs.next(this.postFlightTransform(response));
obs.complete();
} else {
// Treat the complete response as partial, then run the postFlightRequests.
obs.next({
...this.postFlightTransform(response),
isPartial: true,
isRunning: true,
});

If needed, it transforms the response to a partial response and update the body with the postflight request.
This works correctly if the postflight is actually necessary, but due to the current implementation the postflight request is always "applied" even if not needed, causing a subsequent request to be sent to ES.
This results to an increase of:

  • more time spent unnecessary before returning the results to the client
  • 1 more unnecessary search strategy that cache check
  • 1 more unnecessary run of tabify

Analysis
The current method that checks if a request needs a subsequent post-flight request relies on a loose check from the function hasPostFlightRequests. This function checks if the agg property type.postFlightRequest is a function.

private hasPostFlightRequests() {
const aggs = this.getField('aggs');
if (aggs instanceof AggConfigs) {
return aggs.aggs.some(
(agg) => agg.enabled && typeof agg.type.postFlightRequest === 'function'
);
} else {
return false;
}
}

This function is there even if is not required. For example in a terms aggregation without the other bucket the function is still there but just return its identity

postFlightRequest: createOtherBucketPostFlightRequest(constructSingleTermOtherFilter),

All the other cases this is defaulted to an identity function, so the hasPostFlightRequests function will always return true.
this.postFlightRequest = config.postFlightRequest || identity;

@ppisljar ppisljar added Feature:Search Querying infrastructure in Kibana Team:Visualizations Visualization editors, elastic-charts and infrastructure labels May 8, 2024
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Search Querying infrastructure in Kibana Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants