@opensearch-project/opensearch 1.1.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +31 -0
  3. package/.prettierrc.json +5 -0
  4. package/.whitesource +15 -0
  5. package/ADMINS.md +13 -31
  6. package/CHANGELOG.md +24 -0
  7. package/COMPATIBILITY.md +27 -0
  8. package/DEVELOPER_GUIDE.md +22 -5
  9. package/MAINTAINERS.md +15 -70
  10. package/Makefile +2 -12
  11. package/README.md +19 -123
  12. package/RELEASING.md +3 -3
  13. package/SECURITY.md +1 -1
  14. package/USER_GUIDE.md +197 -0
  15. package/api/api/bulk.js +54 -28
  16. package/api/api/cat.js +355 -266
  17. package/api/api/clear_scroll.js +18 -19
  18. package/api/api/cluster.js +367 -221
  19. package/api/api/count.js +56 -26
  20. package/api/api/create.js +51 -26
  21. package/api/api/dangling_indices.js +96 -53
  22. package/api/api/delete.js +50 -24
  23. package/api/api/delete_by_query.js +89 -27
  24. package/api/api/delete_by_query_rethrottle.js +34 -21
  25. package/api/api/delete_script.js +32 -19
  26. package/api/api/exists.js +56 -24
  27. package/api/api/exists_source.js +61 -29
  28. package/api/api/explain.js +61 -24
  29. package/api/api/features.js +57 -37
  30. package/api/api/field_caps.js +37 -20
  31. package/api/api/get.js +56 -24
  32. package/api/api/get_script.js +31 -19
  33. package/api/api/get_script_context.js +16 -17
  34. package/api/api/get_script_languages.js +16 -17
  35. package/api/api/get_source.js +56 -24
  36. package/api/api/index.js +61 -30
  37. package/api/api/indices.js +1069 -859
  38. package/api/api/info.js +16 -17
  39. package/api/api/ingest.js +133 -98
  40. package/api/api/mget.js +51 -28
  41. package/api/api/msearch.js +50 -28
  42. package/api/api/msearch_template.js +54 -28
  43. package/api/api/mtermvectors.js +49 -26
  44. package/api/api/nodes.js +282 -156
  45. package/api/api/ping.js +16 -17
  46. package/api/api/put_script.js +41 -27
  47. package/api/api/rank_eval.js +38 -22
  48. package/api/api/reindex.js +39 -19
  49. package/api/api/reindex_rethrottle.js +33 -21
  50. package/api/api/render_search_template.js +19 -20
  51. package/api/api/scripts_painless_execute.js +16 -17
  52. package/api/api/scroll.js +32 -19
  53. package/api/api/search.js +109 -26
  54. package/api/api/search_shards.js +37 -20
  55. package/api/api/search_template.js +65 -28
  56. package/api/api/shutdown.js +67 -56
  57. package/api/api/snapshot.js +348 -226
  58. package/api/api/tasks.js +66 -48
  59. package/api/api/terms_enum.js +18 -19
  60. package/api/api/termvectors.js +58 -28
  61. package/api/api/update.js +65 -26
  62. package/api/api/update_by_query.js +90 -25
  63. package/api/api/update_by_query_rethrottle.js +34 -21
  64. package/api/index.js +268 -181
  65. package/api/new.d.ts +2043 -531
  66. package/api/opensearch_dashboards.d.ts +240 -238
  67. package/api/requestParams.d.ts +302 -71
  68. package/api/types.d.ts +6205 -5721
  69. package/api/utils.js +23 -24
  70. package/codecov.yml +2 -2
  71. package/index.d.ts +5203 -1037
  72. package/index.js +154 -143
  73. package/index.mjs +10 -11
  74. package/jenkins/release.JenkinsFile +11 -0
  75. package/lib/Connection.d.ts +38 -28
  76. package/lib/Connection.js +166 -170
  77. package/lib/Helpers.d.ts +108 -68
  78. package/lib/Helpers.js +401 -378
  79. package/lib/Serializer.d.ts +3 -4
  80. package/lib/Serializer.js +40 -41
  81. package/lib/Transport.d.ts +39 -15
  82. package/lib/Transport.js +381 -337
  83. package/lib/aws/AwsSigv4Signer.js +167 -0
  84. package/lib/aws/errors.js +24 -0
  85. package/lib/aws/index.d.ts +39 -0
  86. package/lib/aws/index.js +19 -0
  87. package/lib/errors.d.ts +26 -9
  88. package/lib/errors.js +76 -73
  89. package/lib/pool/BaseConnectionPool.js +101 -99
  90. package/lib/pool/CloudConnectionPool.js +17 -18
  91. package/lib/pool/ConnectionPool.js +106 -107
  92. package/lib/pool/index.d.ts +9 -8
  93. package/lib/pool/index.js +7 -8
  94. package/package.json +37 -15
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -28,71 +27,71 @@
28
27
  * under the License.
29
28
  */
30
29
 
31
- 'use strict'
30
+ 'use strict';
32
31
 
33
- const { URL } = require('url')
34
- const debug = require('debug')('opensearch')
35
- const Connection = require('../Connection')
36
- const noop = () => { }
32
+ const { URL } = require('url');
33
+ const debug = require('debug')('opensearch');
34
+ const Connection = require('../Connection');
35
+ const noop = () => {};
37
36
 
38
37
  class BaseConnectionPool {
39
- constructor (opts) {
38
+ constructor(opts) {
40
39
  // list of nodes and weights
41
- this.connections = []
40
+ this.connections = [];
42
41
  // how many nodes we have in our scheduler
43
- this.size = this.connections.length
44
- this.Connection = opts.Connection
45
- this.emit = opts.emit || noop
46
- this.auth = opts.auth || null
47
- this._ssl = opts.ssl
48
- this._agent = opts.agent
49
- this._proxy = opts.proxy || null
42
+ this.size = this.connections.length;
43
+ this.Connection = opts.Connection;
44
+ this.emit = opts.emit || noop;
45
+ this.auth = opts.auth || null;
46
+ this._ssl = opts.ssl;
47
+ this._agent = opts.agent;
48
+ this._proxy = opts.proxy || null;
50
49
  }
51
50
 
52
- getConnection () {
53
- throw new Error('getConnection must be implemented')
51
+ getConnection() {
52
+ throw new Error('getConnection must be implemented');
54
53
  }
55
54
 
56
- markAlive () {
57
- return this
55
+ markAlive() {
56
+ return this;
58
57
  }
59
58
 
60
- markDead () {
61
- return this
59
+ markDead() {
60
+ return this;
62
61
  }
63
62
 
64
63
  /**
65
64
  * Creates a new connection instance.
66
65
  */
67
- createConnection (opts) {
66
+ createConnection(opts) {
68
67
  if (typeof opts === 'string') {
69
- opts = this.urlToHost(opts)
68
+ opts = this.urlToHost(opts);
70
69
  }
71
70
 
72
71
  if (this.auth !== null) {
73
- opts.auth = this.auth
72
+ opts.auth = this.auth;
74
73
  } else if (opts.url.username !== '' && opts.url.password !== '') {
75
74
  opts.auth = {
76
75
  username: decodeURIComponent(opts.url.username),
77
- password: decodeURIComponent(opts.url.password)
78
- }
76
+ password: decodeURIComponent(opts.url.password),
77
+ };
79
78
  }
80
79
 
81
- if (opts.ssl == null) opts.ssl = this._ssl
80
+ if (opts.ssl == null) opts.ssl = this._ssl;
82
81
  /* istanbul ignore else */
83
- if (opts.agent == null) opts.agent = this._agent
82
+ if (opts.agent == null) opts.agent = this._agent;
84
83
  /* istanbul ignore else */
85
- if (opts.proxy == null) opts.proxy = this._proxy
84
+ if (opts.proxy == null) opts.proxy = this._proxy;
86
85
 
87
- const connection = new this.Connection(opts)
86
+ const connection = new this.Connection(opts);
88
87
 
89
88
  for (const conn of this.connections) {
90
89
  if (conn.id === connection.id) {
91
- throw new Error(`Connection with id '${connection.id}' is already present`)
90
+ throw new Error(`Connection with id '${connection.id}' is already present`);
92
91
  }
93
92
  }
94
93
 
95
- return connection
94
+ return connection;
96
95
  }
97
96
 
98
97
  /**
@@ -101,24 +100,24 @@ class BaseConnectionPool {
101
100
  * @param {object|string} host
102
101
  * @returns {ConnectionPool}
103
102
  */
104
- addConnection (opts) {
103
+ addConnection(opts) {
105
104
  if (Array.isArray(opts)) {
106
- return opts.forEach(o => this.addConnection(o))
105
+ return opts.forEach((o) => this.addConnection(o));
107
106
  }
108
107
 
109
108
  if (typeof opts === 'string') {
110
- opts = this.urlToHost(opts)
109
+ opts = this.urlToHost(opts);
111
110
  }
112
111
 
113
- const connectionById = this.connections.find(c => c.id === opts.id)
114
- const connectionByUrl = this.connections.find(c => c.id === opts.url.href)
112
+ const connectionById = this.connections.find((c) => c.id === opts.id);
113
+ const connectionByUrl = this.connections.find((c) => c.id === opts.url.href);
115
114
 
116
115
  if (connectionById || connectionByUrl) {
117
- throw new Error(`Connection with id '${opts.id || opts.url.href}' is already present`)
116
+ throw new Error(`Connection with id '${opts.id || opts.url.href}' is already present`);
118
117
  }
119
118
 
120
- this.update([...this.connections, opts])
121
- return this.connections[this.size - 1]
119
+ this.update([...this.connections, opts]);
120
+ return this.connections[this.size - 1];
122
121
  }
123
122
 
124
123
  /**
@@ -127,9 +126,9 @@ class BaseConnectionPool {
127
126
  * @param {object} connection
128
127
  * @returns {ConnectionPool}
129
128
  */
130
- removeConnection (connection) {
131
- debug('Removing connection', connection)
132
- return this.update(this.connections.filter(c => c.id !== connection.id))
129
+ removeConnection(connection) {
130
+ debug('Removing connection', connection);
131
+ return this.update(this.connections.filter((c) => c.id !== connection.id));
133
132
  }
134
133
 
135
134
  /**
@@ -137,18 +136,18 @@ class BaseConnectionPool {
137
136
  *
138
137
  * @returns {ConnectionPool}
139
138
  */
140
- empty (callback) {
141
- debug('Emptying the connection pool')
142
- let openConnections = this.size
143
- this.connections.forEach(connection => {
139
+ empty(callback) {
140
+ debug('Emptying the connection pool');
141
+ let openConnections = this.size;
142
+ this.connections.forEach((connection) => {
144
143
  connection.close(() => {
145
144
  if (--openConnections === 0) {
146
- this.connections = []
147
- this.size = this.connections.length
148
- callback()
145
+ this.connections = [];
146
+ this.size = this.connections.length;
147
+ callback();
149
148
  }
150
- })
151
- })
149
+ });
150
+ });
152
151
  }
153
152
 
154
153
  /**
@@ -157,49 +156,49 @@ class BaseConnectionPool {
157
156
  * @param {array} array of connections
158
157
  * @returns {ConnectionPool}
159
158
  */
160
- update (nodes) {
161
- debug('Updating the connection pool')
162
- const newConnections = []
163
- const oldConnections = []
159
+ update(nodes) {
160
+ debug('Updating the connection pool');
161
+ const newConnections = [];
162
+ const oldConnections = [];
164
163
 
165
164
  for (const node of nodes) {
166
165
  // if we already have a given connection in the pool
167
166
  // we mark it as alive and we do not close the connection
168
167
  // to avoid socket issues
169
- const connectionById = this.connections.find(c => c.id === node.id)
170
- const connectionByUrl = this.connections.find(c => c.id === node.url.href)
168
+ const connectionById = this.connections.find((c) => c.id === node.id);
169
+ const connectionByUrl = this.connections.find((c) => c.id === node.url.href);
171
170
  if (connectionById) {
172
- debug(`The connection with id '${node.id}' is already present`)
173
- this.markAlive(connectionById)
174
- newConnections.push(connectionById)
171
+ debug(`The connection with id '${node.id}' is already present`);
172
+ this.markAlive(connectionById);
173
+ newConnections.push(connectionById);
175
174
  // in case the user has passed a single url (or an array of urls),
176
175
  // the connection id will be the full href; to avoid closing valid connections
177
176
  // because are not present in the pool, we check also the node url,
178
177
  // and if is already present we update its id with the opensearch provided one.
179
178
  } else if (connectionByUrl) {
180
- connectionByUrl.id = node.id
181
- this.markAlive(connectionByUrl)
182
- newConnections.push(connectionByUrl)
179
+ connectionByUrl.id = node.id;
180
+ this.markAlive(connectionByUrl);
181
+ newConnections.push(connectionByUrl);
183
182
  } else {
184
- newConnections.push(this.createConnection(node))
183
+ newConnections.push(this.createConnection(node));
185
184
  }
186
185
  }
187
186
 
188
- const ids = nodes.map(c => c.id)
187
+ const ids = nodes.map((c) => c.id);
189
188
  // remove all the dead connections and old connections
190
189
  for (const connection of this.connections) {
191
190
  if (ids.indexOf(connection.id) === -1) {
192
- oldConnections.push(connection)
191
+ oldConnections.push(connection);
193
192
  }
194
193
  }
195
194
 
196
195
  // close old connections
197
- oldConnections.forEach(connection => connection.close())
196
+ oldConnections.forEach((connection) => connection.close());
198
197
 
199
- this.connections = newConnections
200
- this.size = this.connections.length
198
+ this.connections = newConnections;
199
+ this.size = this.connections.length;
201
200
 
202
- return this
201
+ return this;
203
202
  }
204
203
 
205
204
  /**
@@ -208,12 +207,12 @@ class BaseConnectionPool {
208
207
  * @param {object} nodes
209
208
  * @returns {array} hosts
210
209
  */
211
- nodesToHost (nodes, protocol) {
212
- const ids = Object.keys(nodes)
213
- const hosts = []
210
+ nodesToHost(nodes, protocol) {
211
+ const ids = Object.keys(nodes);
212
+ const hosts = [];
214
213
 
215
214
  for (let i = 0, len = ids.length; i < len; i++) {
216
- const node = nodes[ids[i]]
215
+ const node = nodes[ids[i]];
217
216
  // If there is no protocol in
218
217
  // the `publish_address` new URL will throw
219
218
  // the publish_address can have two forms:
@@ -221,36 +220,39 @@ class BaseConnectionPool {
221
220
  // - hostname/ip:port
222
221
  // if we encounter the second case, we should
223
222
  // use the hostname instead of the ip
224
- let address = node.http.publish_address
225
- const parts = address.split('/')
223
+ let address = node.http.publish_address;
224
+ const parts = address.split('/');
226
225
  // the url is in the form of hostname/ip:port
227
226
  if (parts.length > 1) {
228
- const hostname = parts[0]
229
- const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1)
230
- address = `${hostname}:${port}`
227
+ const hostname = parts[0];
228
+ const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1);
229
+ address = `${hostname}:${port}`;
231
230
  }
232
231
 
233
- address = address.slice(0, 4) === 'http'
234
- /* istanbul ignore next */
235
- ? address
236
- : `${protocol}//${address}`
232
+ address =
233
+ address.slice(0, 4) === 'http'
234
+ ? /* istanbul ignore next */
235
+ address
236
+ : `${protocol}//${address}`;
237
237
  const roles = node.roles.reduce((acc, role) => {
238
- acc[role] = true
239
- return acc
240
- }, {})
238
+ acc[role] = true;
239
+ return acc;
240
+ }, {});
241
241
 
242
242
  hosts.push({
243
243
  url: new URL(address),
244
244
  id: ids[i],
245
- roles: Object.assign({
246
- [Connection.roles.MASTER]: false,
247
- [Connection.roles.DATA]: false,
248
- [Connection.roles.INGEST]: false
249
- }, roles)
250
- })
245
+ roles: Object.assign(
246
+ {
247
+ [Connection.roles.DATA]: false,
248
+ [Connection.roles.INGEST]: false,
249
+ },
250
+ roles
251
+ ),
252
+ });
251
253
  }
252
254
 
253
- return hosts
255
+ return hosts;
254
256
  }
255
257
 
256
258
  /**
@@ -259,11 +261,11 @@ class BaseConnectionPool {
259
261
  * @param {string} url
260
262
  * @returns {object} host
261
263
  */
262
- urlToHost (url) {
264
+ urlToHost(url) {
263
265
  return {
264
- url: new URL(url)
265
- }
266
+ url: new URL(url),
267
+ };
266
268
  }
267
269
  }
268
270
 
269
- module.exports = BaseConnectionPool
271
+ module.exports = BaseConnectionPool;
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -28,14 +27,14 @@
28
27
  * under the License.
29
28
  */
30
29
 
31
- 'use strict'
30
+ 'use strict';
32
31
 
33
- const BaseConnectionPool = require('./BaseConnectionPool')
32
+ const BaseConnectionPool = require('./BaseConnectionPool');
34
33
 
35
34
  class CloudConnectionPool extends BaseConnectionPool {
36
- constructor (opts) {
37
- super(opts)
38
- this.cloudConnection = null
35
+ constructor(opts) {
36
+ super(opts);
37
+ this.cloudConnection = null;
39
38
  }
40
39
 
41
40
  /**
@@ -43,8 +42,8 @@ class CloudConnectionPool extends BaseConnectionPool {
43
42
  *
44
43
  * @returns {object} connection
45
44
  */
46
- getConnection () {
47
- return this.cloudConnection
45
+ getConnection() {
46
+ return this.cloudConnection;
48
47
  }
49
48
 
50
49
  /**
@@ -52,11 +51,11 @@ class CloudConnectionPool extends BaseConnectionPool {
52
51
  *
53
52
  * @returns {ConnectionPool}
54
53
  */
55
- empty (callback) {
54
+ empty(callback) {
56
55
  super.empty(() => {
57
- this.cloudConnection = null
58
- callback()
59
- })
56
+ this.cloudConnection = null;
57
+ callback();
58
+ });
60
59
  }
61
60
 
62
61
  /**
@@ -65,11 +64,11 @@ class CloudConnectionPool extends BaseConnectionPool {
65
64
  * @param {array} array of connections
66
65
  * @returns {ConnectionPool}
67
66
  */
68
- update (connections) {
69
- super.update(connections)
70
- this.cloudConnection = this.connections[0]
71
- return this
67
+ update(connections) {
68
+ super.update(connections);
69
+ this.cloudConnection = this.connections[0];
70
+ return this;
72
71
  }
73
72
  }
74
73
 
75
- module.exports = CloudConnectionPool
74
+ module.exports = CloudConnectionPool;