Skip to content

Commit e1af4e4

Browse files
Daniilkibanamachine
andauthored
Fix request with disabled aggregation (#85696) (#86627)
* Fix request with disabled aggregation * Update unit tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent a3b4cac commit e1af4e4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/plugins/data/common/search/expressions/esaggs/request_handler.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ describe('esaggs expression function - public', () => {
151151
});
152152
});
153153

154-
test('calls agg.postFlightRequest if it exiests', async () => {
154+
test('calls agg.postFlightRequest if it exiests and agg is enabled', async () => {
155+
mockParams.aggs.aggs[0].enabled = true;
155156
await handleRequest(mockParams);
156157
expect(mockParams.aggs.aggs[0].type.postFlightRequest).toHaveBeenCalledTimes(1);
157158

@@ -161,6 +162,12 @@ describe('esaggs expression function - public', () => {
161162
expect(async () => await handleRequest(mockParams)).not.toThrowError();
162163
});
163164

165+
test('should skip agg.postFlightRequest call if the agg is disabled', async () => {
166+
mockParams.aggs.aggs[0].enabled = false;
167+
await handleRequest(mockParams);
168+
expect(mockParams.aggs.aggs[0].type.postFlightRequest).toHaveBeenCalledTimes(0);
169+
});
170+
164171
test('tabifies response data', async () => {
165172
await handleRequest(mockParams);
166173
expect(tabifyAggResponse).toHaveBeenCalledWith(

src/plugins/data/common/search/expressions/esaggs/request_handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const handleRequest = async ({
175175
// response data incorrectly in the inspector.
176176
let response = (searchSource as any).rawResponse;
177177
for (const agg of aggs.aggs) {
178-
if (typeof agg.type.postFlightRequest === 'function') {
178+
if (agg.enabled && typeof agg.type.postFlightRequest === 'function') {
179179
response = await agg.type.postFlightRequest(
180180
response,
181181
aggs,

0 commit comments

Comments
 (0)