Skip to content

Commit 77148ca

Browse files
author
Liza K
committed
shimmy
1 parent 9cc2922 commit 77148ca

1 file changed

Lines changed: 38 additions & 30 deletions

File tree

src/plugins/data/server/search/search_service.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
SharedGlobalConfig,
3030
StartServicesAccessor,
3131
} from 'src/core/server';
32-
import { catchError, first, switchMap } from 'rxjs/operators';
32+
import { catchError, first, map, switchMap } from 'rxjs/operators';
3333
import { BfetchServerSetup } from 'src/plugins/bfetch/server';
3434
import { ExpressionsServerSetup } from 'src/plugins/expressions/server';
3535
import {
@@ -44,7 +44,7 @@ import { AggsService } from './aggs';
4444

4545
import { FieldFormatsStart } from '../field_formats';
4646
import { IndexPatternsServiceStart } from '../index_patterns';
47-
import { getCallMsearch, registerMsearchRoute, registerSearchRoute } from './routes';
47+
import { getCallMsearch, registerMsearchRoute, registerSearchRoute, shimHitsTotal } from './routes';
4848
import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search';
4949
import { DataPluginStart } from '../plugin';
5050
import { UsageCollectionSetup } from '../../../usage_collection/server';
@@ -152,35 +152,43 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
152152
)
153153
);
154154

155-
bfetch.addBatchProcessingRoute<{ request: any; options?: ISearchOptions }, any>(
156-
'/internal/bsearch',
157-
(request) => {
158-
const search = this.asScopedProvider(this.coreStart!)(request);
159-
160-
return {
161-
onBatchItem: async ({ request: requestData, options }) => {
162-
return search
163-
.search(requestData, options)
164-
.pipe(
165-
first(),
166-
catchError((err) => {
167-
// eslint-disable-next-line no-throw-literal
168-
throw {
169-
statusCode: err.statusCode || 500,
170-
body: {
171-
message: err.message,
172-
attributes: {
173-
error: err.body?.error || err.message,
174-
},
155+
bfetch.addBatchProcessingRoute<
156+
{ request: IKibanaSearchResponse; options?: ISearchOptions },
157+
any
158+
>('/internal/bsearch', (request) => {
159+
const search = this.asScopedProvider(this.coreStart!)(request);
160+
161+
return {
162+
onBatchItem: async ({ request: requestData, options }) => {
163+
return search
164+
.search(requestData, options)
165+
.pipe(
166+
first(),
167+
map((response) => {
168+
return {
169+
...response,
170+
...{
171+
rawResponse: shimHitsTotal(response.rawResponse),
172+
},
173+
};
174+
}),
175+
catchError((err) => {
176+
// eslint-disable-next-line no-throw-literal
177+
throw {
178+
statusCode: err.statusCode || 500,
179+
body: {
180+
message: err.message,
181+
attributes: {
182+
error: err.body?.error || err.message,
175183
},
176-
};
177-
})
178-
)
179-
.toPromise();
180-
},
181-
};
182-
}
183-
);
184+
},
185+
};
186+
})
187+
)
188+
.toPromise();
189+
},
190+
};
191+
});
184192

185193
core.savedObjects.registerType(searchTelemetry);
186194
if (usageCollection) {

0 commit comments

Comments
 (0)