feat: add support for querystring in options object (#779)
In very few cases, some API uses the same key for both url and query params, such as the bulk method. The client is not designed to handle such cases since accepts both url and query keys in the same object, and the url parameter will always take precedence. This pr fixes this edge case by adding a `querystring` key in the options object. Fixes: https://github.com/elastic/elasticsearch-js/pull/778 ```js client.bulk({ index: 'index', type: '_doc', body: [...] }, { querystring: { type: '_doc' } }, console.log) ```
This commit is contained in:
committed by
delvedor
parent
a3e3d57247
commit
68c4dd29fb
7
lib/Transport.d.ts
vendored
7
lib/Transport.d.ts
vendored
@ -80,9 +80,9 @@ declare type anyObject = {
|
||||
export interface TransportRequestParams {
|
||||
method: string;
|
||||
path: string;
|
||||
body?: anyObject,
|
||||
bulkBody?: anyObject,
|
||||
querystring: anyObject
|
||||
body?: anyObject;
|
||||
bulkBody?: anyObject;
|
||||
querystring?: anyObject;
|
||||
}
|
||||
|
||||
export interface TransportRequestOptions {
|
||||
@ -91,6 +91,7 @@ export interface TransportRequestOptions {
|
||||
maxRetries?: number;
|
||||
asStream?: boolean;
|
||||
headers?: anyObject;
|
||||
querystring?: anyObject;
|
||||
compression?: string;
|
||||
warnings?: [string];
|
||||
}
|
||||
|
||||
@ -166,7 +166,13 @@ class Transport {
|
||||
|
||||
params.headers = headers
|
||||
// serializes the querystring
|
||||
params.querystring = this.serializer.qserialize(params.querystring)
|
||||
if (options.querystring == null) {
|
||||
params.querystring = this.serializer.qserialize(params.querystring)
|
||||
} else {
|
||||
params.querystring = this.serializer.qserialize(
|
||||
Object.assign({}, params.querystring, options.querystring)
|
||||
)
|
||||
}
|
||||
|
||||
meta.request.params = params
|
||||
meta.request.options = options
|
||||
|
||||
Reference in New Issue
Block a user