diff --git a/x-pack/plugins/data_enhanced/common/search/es_search/es_search_rxjs_utils.ts b/x-pack/plugins/data_enhanced/common/search/es_search/es_search_rxjs_utils.ts index 2d5d09fd0205e3..2f510146e08699 100644 --- a/x-pack/plugins/data_enhanced/common/search/es_search/es_search_rxjs_utils.ts +++ b/x-pack/plugins/data_enhanced/common/search/es_search/es_search_rxjs_utils.ts @@ -5,7 +5,8 @@ */ import { of, merge, timer, throwError } from 'rxjs'; -import { takeWhile, switchMap, expand, mergeMap, tap } from 'rxjs/operators'; +import { map, takeWhile, switchMap, expand, mergeMap, tap } from 'rxjs/operators'; +import { ApiResponse } from '@elastic/elasticsearch'; import { AbortError, @@ -35,6 +36,15 @@ export const doPartialSearch = ( takeWhile((response) => !isCompleteResponse(response), true) ); +export const normalizeEqlResponse = () => + map((eqlResponse) => ({ + ...eqlResponse, + body: { + ...eqlResponse.body, + ...eqlResponse, + }, + })); + export const throwOnEsError = () => mergeMap((r: IKibanaSearchResponse) => isErrorResponse(r) ? merge(of(r), throwError(new AbortError())) : of(r) diff --git a/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.test.ts b/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.test.ts index 88aaee8eb7da2d..cd8428efa48511 100644 --- a/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.test.ts +++ b/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.test.ts @@ -22,6 +22,8 @@ const getMockEqlResponse = () => ({ sequences: [], }, }, + meta: {}, + statusCode: 200, }); describe('EQL search strategy', () => { @@ -193,5 +195,24 @@ describe('EQL search strategy', () => { expect(requestOptions).toEqual(expect.objectContaining({ ignore: [400] })); }); }); + + describe('response', () => { + it('contains a rawResponse with body and meta', async () => { + const eqlSearch = await eqlSearchStrategyProvider(mockLogger); + const response = await eqlSearch + .search({ id: 'my-search-id', options: { ignore: [400] } }, {}, mockDeps) + .toPromise(); + + expect(response).toEqual( + expect.objectContaining({ + rawResponse: expect.objectContaining({ + body: expect.any(Object), + meta: expect.any(Object), + statusCode: 200, + }), + }) + ); + }); + }); }); }); diff --git a/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.ts index a75f2617a9bf35..7b3d0db450b044 100644 --- a/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/eql_search_strategy.ts @@ -8,7 +8,10 @@ import type { Logger } from 'kibana/server'; import type { ApiResponse } from '@elastic/elasticsearch'; import { search } from '../../../../../src/plugins/data/server'; -import { doPartialSearch } from '../../common/search/es_search/es_search_rxjs_utils'; +import { + doPartialSearch, + normalizeEqlResponse, +} from '../../common/search/es_search/es_search_rxjs_utils'; import { getAsyncOptions, getDefaultSearchParams } from './get_default_search_params'; import type { ISearchStrategy, IEsRawSearchResponse } from '../../../../../src/plugins/data/server'; @@ -64,7 +67,7 @@ export const eqlSearchStrategyProvider = ( (response) => response.body.id, request.id, options - ).pipe(utils.toKibanaSearchResponse()); + ).pipe(normalizeEqlResponse(), utils.toKibanaSearchResponse()); }, }; };