[Search] Send ID in path, rather than body (#62889)

* [Search] Send ID in path, rather than body

* Fix typo in merge

* Update docs

* Revert to using POST instead of GET

* Revert accidental change

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Lukas Olson 2020-08-03 15:13:27 -07:00 committed by GitHub
parent 06412ae770
commit 584804047a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 17 deletions

View file

@ -35,7 +35,7 @@ export declare class SearchInterceptor
| Method | Modifiers | Description |
| --- | --- | --- |
| [runSearch(request, combinedSignal)](./kibana-plugin-plugins-data-public.searchinterceptor.runsearch.md) | | |
| [runSearch(request, signal)](./kibana-plugin-plugins-data-public.searchinterceptor.runsearch.md) | | |
| [search(request, options)](./kibana-plugin-plugins-data-public.searchinterceptor.search.md) | | Searches using the given <code>search</code> method. Overrides the <code>AbortSignal</code> with one that will abort either when <code>cancelPending</code> is called, when the request times out, or when the original <code>AbortSignal</code> is aborted. Updates the <code>pendingCount</code> when the request is started/finalized. |
| [setupTimers(options)](./kibana-plugin-plugins-data-public.searchinterceptor.setuptimers.md) | | |

View file

@ -7,7 +7,7 @@
<b>Signature:</b>
```typescript
protected runSearch(request: IEsSearchRequest, combinedSignal: AbortSignal): Observable<IEsSearchResponse>;
protected runSearch(request: IEsSearchRequest, signal: AbortSignal): Observable<IEsSearchResponse>;
```
## Parameters
@ -15,7 +15,7 @@ protected runSearch(request: IEsSearchRequest, combinedSignal: AbortSignal): Obs
| Parameter | Type | Description |
| --- | --- | --- |
| request | <code>IEsSearchRequest</code> | |
| combinedSignal | <code>AbortSignal</code> | |
| signal | <code>AbortSignal</code> | |
<b>Returns:</b>

View file

@ -1661,7 +1661,7 @@ export class SearchInterceptor {
// (undocumented)
protected readonly requestTimeout?: number | undefined;
// (undocumented)
protected runSearch(request: IEsSearchRequest, combinedSignal: AbortSignal): Observable<IEsSearchResponse>;
protected runSearch(request: IEsSearchRequest, signal: AbortSignal): Observable<IEsSearchResponse>;
search(request: IEsSearchRequest, options?: ISearchOptions): Observable<IEsSearchResponse>;
// (undocumented)
protected setupTimers(options?: ISearchOptions): {

View file

@ -92,16 +92,14 @@ export class SearchInterceptor {
protected runSearch(
request: IEsSearchRequest,
combinedSignal: AbortSignal
signal: AbortSignal
): Observable<IEsSearchResponse> {
return from(
this.deps.http.fetch({
path: `/internal/search/es`,
method: 'POST',
body: JSON.stringify(request),
signal: combinedSignal,
})
);
const { id, ...searchRequest } = request;
const path = id != null ? `/internal/search/es/${id}` : '/internal/search/es';
const method = 'POST';
const body = JSON.stringify(id != null ? {} : searchRequest);
const response = this.deps.http.fetch({ path, method, body, signal });
return from(response);
}
/**

View file

@ -27,9 +27,12 @@ export function registerSearchRoute(core: CoreSetup<object, DataPluginStart>): v
router.post(
{
path: '/internal/search/{strategy}',
path: '/internal/search/{strategy}/{id?}',
validate: {
params: schema.object({ strategy: schema.string() }),
params: schema.object({
strategy: schema.string(),
id: schema.maybe(schema.string()),
}),
query: schema.object({}, { unknowns: 'allow' }),
@ -38,13 +41,13 @@ export function registerSearchRoute(core: CoreSetup<object, DataPluginStart>): v
},
async (context, request, res) => {
const searchRequest = request.body;
const { strategy } = request.params;
const { strategy, id } = request.params;
const signal = getRequestAbortedSignal(request.events.aborted$);
const [, , selfStart] = await core.getStartServices();
try {
const response = await selfStart.search.search(context, searchRequest, {
const response = await selfStart.search.search(context, id ? { id } : searchRequest, {
signal,
strategy,
});