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.
https://github.com/elastic/kibana/blob/74fdd1b5f25c783ef95b3fddb2eaef03ff597345/src/plugins/data/common/search/search_source/search_source.ts#L539-L548
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.
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. https://github.com/elastic/kibana/blob/74fdd1b5f25c783ef95b3fddb2eaef03ff597345/src/plugins/data/common/search/search_source/search_source.ts#L539-L548 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: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 propertytype.postFlightRequest
is a function.https://github.com/elastic/kibana/blob/74fdd1b5f25c783ef95b3fddb2eaef03ff597345/src/plugins/data/common/search/search_source/search_source.ts#L474-L483
This function is there even if is not required. For example in a
terms
aggregation without theother
bucket the function is still there but just return its identity https://github.com/elastic/kibana/blob/74fdd1b5f25c783ef95b3fddb2eaef03ff597345/src/plugins/data/common/search/aggs/buckets/terms.ts#L93 All the other cases this is defaulted to anidentity
function, so thehasPostFlightRequests
function will always return true. https://github.com/elastic/kibana/blob/74fdd1b5f25c783ef95b3fddb2eaef03ff597345/src/plugins/data/common/search/aggs/agg_type.ts#L311