Skip to content

Commit d5256e2

Browse files
committed
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: #778 ```js client.bulk({ index: 'index', type: '_doc', body: [...] }, { querystring: { type: '_doc' } }, console.log) ```
1 parent 55fd039 commit d5256e2

File tree

261 files changed

+1051
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+1051
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ The supported *request specific options* are:
128128
requestTimeout: number, // client default
129129
maxRetries: number, // default `5`
130130
asStream: boolean, // default `false`
131-
headers: object // default `null`
131+
compression: string, // default `false`
132+
headers: object, // default `null`
133+
querystring: object // default `null`
132134
}
133135
```
134136

api/api/bulk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function buildBulk (opts) {
151151
maxRetries: options.maxRetries || null,
152152
asStream: options.asStream || false,
153153
headers: options.headers || null,
154+
querystring: options.querystring || null,
154155
compression: options.compression || false,
155156
warnings
156157
}

api/api/cat.aliases.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function buildCatAliases (opts) {
131131
maxRetries: options.maxRetries || null,
132132
asStream: options.asStream || false,
133133
headers: options.headers || null,
134+
querystring: options.querystring || null,
134135
compression: options.compression || false,
135136
warnings
136137
}

api/api/cat.allocation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function buildCatAllocation (opts) {
133133
maxRetries: options.maxRetries || null,
134134
asStream: options.asStream || false,
135135
headers: options.headers || null,
136+
querystring: options.querystring || null,
136137
compression: options.compression || false,
137138
warnings
138139
}

api/api/cat.count.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function buildCatCount (opts) {
131131
maxRetries: options.maxRetries || null,
132132
asStream: options.asStream || false,
133133
headers: options.headers || null,
134+
querystring: options.querystring || null,
134135
compression: options.compression || false,
135136
warnings
136137
}

api/api/cat.fielddata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function buildCatFielddata (opts) {
135135
maxRetries: options.maxRetries || null,
136136
asStream: options.asStream || false,
137137
headers: options.headers || null,
138+
querystring: options.querystring || null,
138139
compression: options.compression || false,
139140
warnings
140141
}

api/api/cat.health.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ function buildCatHealth (opts) {
128128
maxRetries: options.maxRetries || null,
129129
asStream: options.asStream || false,
130130
headers: options.headers || null,
131+
querystring: options.querystring || null,
131132
compression: options.compression || false,
132133
warnings
133134
}

api/api/cat.help.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function buildCatHelp (opts) {
115115
maxRetries: options.maxRetries || null,
116116
asStream: options.asStream || false,
117117
headers: options.headers || null,
118+
querystring: options.querystring || null,
118119
compression: options.compression || false,
119120
warnings
120121
}

api/api/cat.indices.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function buildCatIndices (opts) {
137137
maxRetries: options.maxRetries || null,
138138
asStream: options.asStream || false,
139139
headers: options.headers || null,
140+
querystring: options.querystring || null,
140141
compression: options.compression || false,
141142
warnings
142143
}

api/api/cat.master.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function buildCatMaster (opts) {
126126
maxRetries: options.maxRetries || null,
127127
asStream: options.asStream || false,
128128
headers: options.headers || null,
129+
querystring: options.querystring || null,
129130
compression: options.compression || false,
130131
warnings
131132
}

api/api/cat.nodeattrs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function buildCatNodeattrs (opts) {
126126
maxRetries: options.maxRetries || null,
127127
asStream: options.asStream || false,
128128
headers: options.headers || null,
129+
querystring: options.querystring || null,
129130
compression: options.compression || false,
130131
warnings
131132
}

api/api/cat.nodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function buildCatNodes (opts) {
129129
maxRetries: options.maxRetries || null,
130130
asStream: options.asStream || false,
131131
headers: options.headers || null,
132+
querystring: options.querystring || null,
132133
compression: options.compression || false,
133134
warnings
134135
}

api/api/cat.pending_tasks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function buildCatPendingTasks (opts) {
126126
maxRetries: options.maxRetries || null,
127127
asStream: options.asStream || false,
128128
headers: options.headers || null,
129+
querystring: options.querystring || null,
129130
compression: options.compression || false,
130131
warnings
131132
}

api/api/cat.plugins.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function buildCatPlugins (opts) {
126126
maxRetries: options.maxRetries || null,
127127
asStream: options.asStream || false,
128128
headers: options.headers || null,
129+
querystring: options.querystring || null,
129130
compression: options.compression || false,
130131
warnings
131132
}

api/api/cat.recovery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function buildCatRecovery (opts) {
131131
maxRetries: options.maxRetries || null,
132132
asStream: options.asStream || false,
133133
headers: options.headers || null,
134+
querystring: options.querystring || null,
134135
compression: options.compression || false,
135136
warnings
136137
}

api/api/cat.repositories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function buildCatRepositories (opts) {
126126
maxRetries: options.maxRetries || null,
127127
asStream: options.asStream || false,
128128
headers: options.headers || null,
129+
querystring: options.querystring || null,
129130
compression: options.compression || false,
130131
warnings
131132
}

api/api/cat.segments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ function buildCatSegments (opts) {
128128
maxRetries: options.maxRetries || null,
129129
asStream: options.asStream || false,
130130
headers: options.headers || null,
131+
querystring: options.querystring || null,
131132
compression: options.compression || false,
132133
warnings
133134
}

api/api/cat.shards.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function buildCatShards (opts) {
133133
maxRetries: options.maxRetries || null,
134134
asStream: options.asStream || false,
135135
headers: options.headers || null,
136+
querystring: options.querystring || null,
136137
compression: options.compression || false,
137138
warnings
138139
}

api/api/cat.snapshots.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function buildCatSnapshots (opts) {
132132
maxRetries: options.maxRetries || null,
133133
asStream: options.asStream || false,
134134
headers: options.headers || null,
135+
querystring: options.querystring || null,
135136
compression: options.compression || false,
136137
warnings
137138
}

api/api/cat.tasks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function buildCatTasks (opts) {
131131
maxRetries: options.maxRetries || null,
132132
asStream: options.asStream || false,
133133
headers: options.headers || null,
134+
querystring: options.querystring || null,
134135
compression: options.compression || false,
135136
warnings
136137
}

api/api/cat.templates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function buildCatTemplates (opts) {
131131
maxRetries: options.maxRetries || null,
132132
asStream: options.asStream || false,
133133
headers: options.headers || null,
134+
querystring: options.querystring || null,
134135
compression: options.compression || false,
135136
warnings
136137
}

api/api/cat.thread_pool.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function buildCatThreadPool (opts) {
133133
maxRetries: options.maxRetries || null,
134134
asStream: options.asStream || false,
135135
headers: options.headers || null,
136+
querystring: options.querystring || null,
136137
compression: options.compression || false,
137138
warnings
138139
}

api/api/ccr.delete_auto_follow_pattern.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function buildCcrDeleteAutoFollowPattern (opts) {
107107
maxRetries: options.maxRetries || null,
108108
asStream: options.asStream || false,
109109
headers: options.headers || null,
110+
querystring: options.querystring || null,
110111
compression: options.compression || false,
111112
warnings
112113
}

api/api/ccr.follow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function buildCcrFollow (opts) {
114114
maxRetries: options.maxRetries || null,
115115
asStream: options.asStream || false,
116116
headers: options.headers || null,
117+
querystring: options.querystring || null,
117118
compression: options.compression || false,
118119
warnings
119120
}

api/api/ccr.follow_info.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
'use strict'
21+
22+
/* eslint camelcase: 0 */
23+
/* eslint no-unused-vars: 0 */
24+
25+
function buildCcrFollowInfo (opts) {
26+
// eslint-disable-next-line no-unused-vars
27+
const { makeRequest, ConfigurationError, result } = opts
28+
/**
29+
* Perform a [ccr.follow_info](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html) request
30+
*
31+
* @param {list} index - A comma-separated list of index patterns; use `_all` to perform the operation on all indices
32+
*/
33+
34+
const acceptedQuerystring = [
35+
36+
]
37+
38+
const snakeCase = {
39+
40+
}
41+
42+
return function ccrFollowInfo (params, options, callback) {
43+
options = options || {}
44+
if (typeof options === 'function') {
45+
callback = options
46+
options = {}
47+
}
48+
if (typeof params === 'function' || params == null) {
49+
callback = params
50+
params = {}
51+
options = {}
52+
}
53+
54+
// promises support
55+
if (callback == null) {
56+
return new Promise((resolve, reject) => {
57+
ccrFollowInfo(params, options, (err, body) => {
58+
err ? reject(err) : resolve(body)
59+
})
60+
})
61+
}
62+
63+
// validate headers object
64+
if (options.headers != null && typeof options.headers !== 'object') {
65+
return callback(
66+
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
67+
result
68+
)
69+
}
70+
71+
var warnings = null
72+
var { method, body, index } = params
73+
var querystring = semicopy(params, ['method', 'body', 'index'])
74+
75+
if (method == null) {
76+
method = 'GET'
77+
}
78+
79+
var ignore = options.ignore || null
80+
if (typeof ignore === 'number') {
81+
ignore = [ignore]
82+
}
83+
84+
var path = ''
85+
86+
path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'info'
87+
88+
// build request object
89+
const request = {
90+
method,
91+
path,
92+
body: null,
93+
querystring
94+
}
95+
96+
const requestOptions = {
97+
ignore,
98+
requestTimeout: options.requestTimeout || null,
99+
maxRetries: options.maxRetries || null,
100+
asStream: options.asStream || false,
101+
headers: options.headers || null,
102+
querystring: options.querystring || null,
103+
compression: options.compression || false,
104+
warnings
105+
}
106+
107+
return makeRequest(request, requestOptions, callback)
108+
109+
function semicopy (obj, exclude) {
110+
var target = {}
111+
var keys = Object.keys(obj)
112+
for (var i = 0, len = keys.length; i < len; i++) {
113+
var key = keys[i]
114+
if (exclude.indexOf(key) === -1) {
115+
target[snakeCase[key] || key] = obj[key]
116+
if (acceptedQuerystring.indexOf(snakeCase[key] || key) === -1) {
117+
warnings = warnings || []
118+
warnings.push('Client - Unknown parameter: "' + key + '", sending it as query parameter')
119+
}
120+
}
121+
}
122+
return target
123+
}
124+
}
125+
}
126+
127+
module.exports = buildCcrFollowInfo

api/api/ccr.follow_stats.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function buildCcrFollowStats (opts) {
9999
maxRetries: options.maxRetries || null,
100100
asStream: options.asStream || false,
101101
headers: options.headers || null,
102+
querystring: options.querystring || null,
102103
compression: options.compression || false,
103104
warnings
104105
}

api/api/ccr.get_auto_follow_pattern.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function buildCcrGetAutoFollowPattern (opts) {
103103
maxRetries: options.maxRetries || null,
104104
asStream: options.asStream || false,
105105
headers: options.headers || null,
106+
querystring: options.querystring || null,
106107
compression: options.compression || false,
107108
warnings
108109
}

api/api/ccr.pause_follow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function buildCcrPauseFollow (opts) {
107107
maxRetries: options.maxRetries || null,
108108
asStream: options.asStream || false,
109109
headers: options.headers || null,
110+
querystring: options.querystring || null,
110111
compression: options.compression || false,
111112
warnings
112113
}

api/api/ccr.put_auto_follow_pattern.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function buildCcrPutAutoFollowPattern (opts) {
114114
maxRetries: options.maxRetries || null,
115115
asStream: options.asStream || false,
116116
headers: options.headers || null,
117+
querystring: options.querystring || null,
117118
compression: options.compression || false,
118119
warnings
119120
}

api/api/ccr.resume_follow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function buildCcrResumeFollow (opts) {
108108
maxRetries: options.maxRetries || null,
109109
asStream: options.asStream || false,
110110
headers: options.headers || null,
111+
querystring: options.querystring || null,
111112
compression: options.compression || false,
112113
warnings
113114
}

api/api/ccr.stats.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ function buildCcrStats (opts) {
9898
maxRetries: options.maxRetries || null,
9999
asStream: options.asStream || false,
100100
headers: options.headers || null,
101+
querystring: options.querystring || null,
101102
compression: options.compression || false,
102103
warnings
103104
}

api/api/ccr.unfollow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function buildCcrUnfollow (opts) {
107107
maxRetries: options.maxRetries || null,
108108
asStream: options.asStream || false,
109109
headers: options.headers || null,
110+
querystring: options.querystring || null,
110111
compression: options.compression || false,
111112
warnings
112113
}

api/api/clear_scroll.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function buildClearScroll (opts) {
109109
maxRetries: options.maxRetries || null,
110110
asStream: options.asStream || false,
111111
headers: options.headers || null,
112+
querystring: options.querystring || null,
112113
compression: options.compression || false,
113114
warnings
114115
}

api/api/cluster.allocation_explain.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function buildClusterAllocationExplain (opts) {
110110
maxRetries: options.maxRetries || null,
111111
asStream: options.asStream || false,
112112
headers: options.headers || null,
113+
querystring: options.querystring || null,
113114
compression: options.compression || false,
114115
warnings
115116
}

0 commit comments

Comments
 (0)