Skip to content

Commit

Permalink
shimmy
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Nov 25, 2020
1 parent 9cc2922 commit 77148ca
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
SharedGlobalConfig,
StartServicesAccessor,
} from 'src/core/server';
import { catchError, first, switchMap } from 'rxjs/operators';
import { catchError, first, map, switchMap } from 'rxjs/operators';
import { BfetchServerSetup } from 'src/plugins/bfetch/server';
import { ExpressionsServerSetup } from 'src/plugins/expressions/server';
import {
Expand All @@ -44,7 +44,7 @@ import { AggsService } from './aggs';

import { FieldFormatsStart } from '../field_formats';
import { IndexPatternsServiceStart } from '../index_patterns';
import { getCallMsearch, registerMsearchRoute, registerSearchRoute } from './routes';
import { getCallMsearch, registerMsearchRoute, registerSearchRoute, shimHitsTotal } from './routes';
import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search';
import { DataPluginStart } from '../plugin';
import { UsageCollectionSetup } from '../../../usage_collection/server';
Expand Down Expand Up @@ -152,35 +152,43 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
)
);

bfetch.addBatchProcessingRoute<{ request: any; options?: ISearchOptions }, any>(
'/internal/bsearch',
(request) => {
const search = this.asScopedProvider(this.coreStart!)(request);

return {
onBatchItem: async ({ request: requestData, options }) => {
return search
.search(requestData, options)
.pipe(
first(),
catchError((err) => {
// eslint-disable-next-line no-throw-literal
throw {
statusCode: err.statusCode || 500,
body: {
message: err.message,
attributes: {
error: err.body?.error || err.message,
},
bfetch.addBatchProcessingRoute<
{ request: IKibanaSearchResponse; options?: ISearchOptions },
any
>('/internal/bsearch', (request) => {
const search = this.asScopedProvider(this.coreStart!)(request);

return {
onBatchItem: async ({ request: requestData, options }) => {
return search
.search(requestData, options)
.pipe(
first(),
map((response) => {
return {
...response,
...{
rawResponse: shimHitsTotal(response.rawResponse),
},
};
}),
catchError((err) => {
// eslint-disable-next-line no-throw-literal
throw {
statusCode: err.statusCode || 500,
body: {
message: err.message,
attributes: {
error: err.body?.error || err.message,
},
};
})
)
.toPromise();
},
};
}
);
},
};
})
)
.toPromise();
},
};
});

core.savedObjects.registerType(searchTelemetry);
if (usageCollection) {
Expand Down

0 comments on commit 77148ca

Please sign in to comment.