@opensearch-project/opensearch 2.4.0 → 2.5.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.
package/CHANGELOG.md CHANGED
@@ -11,6 +11,40 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
11
11
  ### Fixed
12
12
  ### Security
13
13
 
14
+ ## [2.5.0]
15
+ ### Added
16
+ - Added deprecation warnings for Index Template APIs ([654](https://github.com/opensearch-project/opensearch-js/pull/645))
17
+ - Added `http` functions: `connect`, `delete`, `get`, `head`, `options`, `patch`, `post`, `put`, and `trace` ([#649](https://github.com/opensearch-project/opensearch-js/pull/649))
18
+ - Added `samples/search.js` and updated `guides/search.md` to provide example to search functionality ([#656](https://github.com/opensearch-project/opensearch-js/pull/656))
19
+ - Added `samples/msearch.js` and `guides/msearch.md` to provide example to multi-search functionality ([#657](https://github.com/opensearch-project/opensearch-js/pull/657))
20
+ - Updated `guides/index_lifecycle.md` to provide example of `ignore_unavailable: true` while deleting indices. ([665](https://github.com/opensearch-project/opensearch-js/pull/665))
21
+ - Add expiration buffer to prevent credentials to expire earlier than request may finish in case AWS SDK v3 is used. ([678](https://github.com/opensearch-project/opensearch-js/pull/678))
22
+ ### Dependencies
23
+ - Bumps `@aws-sdk/types` from 3.418.0 to 3.451.0
24
+ - Bumps `@types/node` from 20.6.5 to 20.9.0
25
+ - Bumps `eslint` from 8.50.0 to 8.54.0
26
+ - Bumps `@babel/traverse` from 7.15.0 to 7.23.2
27
+ - Bumps `eslint-plugin-prettier` from 5.0.0 to 5.0.1
28
+ - Bumps `react-devtools-core` from 4.25.0 to 4.28.4
29
+ - Bumps `simple-git` from 3.20.0 to 3.21.0
30
+ - Bumps `prettier` from 3.0.3 to 3.1.0
31
+ - Bumps `@babel/eslint-parser` from 7.22.15 to 7.23.3
32
+ - Bumps `@types/node` from 20.9.0 to 20.10.7
33
+ - Bumps `eslint` from 8.54.0 to 8.56.0
34
+ - Bumps `@aws-sdk/types` from 3.451.0 to 3.485.0
35
+ - Bumps `prettier` from 3.1.0 to 3.1.1
36
+ - Bumps `eslint-plugin-prettier` from 5.0.1 to 5.1.2
37
+ - Bumps `eslint-config-prettier` from 9.0.0 to 9.1.0
38
+ - Bumps `ora` from 7.0.1 to 8.0.1
39
+ - Bumps `simple-git` from 3.21.0 to 3.22.0
40
+ ### Changed
41
+ ### Deprecated
42
+ ### Removed
43
+ - Removed fixture lines that git-secrets wrongly flagged as passwords/secrets ([654](https://github.com/opensearch-project/opensearch-js/pull/645))
44
+ ### Fixed
45
+ - Add new types to `package.json` exports configuration for ESM support ([#674](https://github.com/opensearch-project/opensearch-js/pull/674))
46
+ ### Security
47
+
14
48
  ## [2.4.0]
15
49
  ### Added
16
50
  - Added Security API ([#606](https://github.com/opensearch-project/opensearch-js/pull/606))
@@ -186,4 +220,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
186
220
 
187
221
  ### Fixed
188
222
 
189
- - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
223
+ - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
package/MAINTAINERS.md CHANGED
@@ -8,7 +8,6 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
8
8
  |-----------------------|-----------------------------------------------|-------------|
9
9
  | Anan Zhuang | [ananzh](https://github.com/ananzh) | Amazon |
10
10
  | Kawika (Rocky) Avilla | [kavilla](https://github.com/kavilla) | Amazon |
11
- | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
12
11
  | Daniel Doubrovkine | [dblock](https://github.com/dblock) | Amazon |
13
12
  | Vacha Shah | [VachaShah](https://github.com/VachaShah) | Amazon |
14
13
  | Theo Truong | [nhtruong](https://github.com/nhtruong) | Amazon |
@@ -17,7 +16,8 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
17
16
 
18
17
  ## Emeritus
19
18
 
20
- | Maintainer | GitHub ID | Affiliation |
21
- |---------------|-------------------------------------------|-------------|
22
- | Bishoy Boktor | [boktorbb](https://github.com/boktorbb) | Amazon |
23
- | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
19
+ | Maintainer | GitHub ID | Affiliation |
20
+ |---------------|-----------------------------------------------|-------------|
21
+ | Bishoy Boktor | [boktorbb](https://github.com/boktorbb) | Amazon |
22
+ | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
23
+ | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
package/USER_GUIDE.md CHANGED
@@ -5,12 +5,17 @@
5
5
  - [Authenticate with Amazon OpenSearch Service](#authenticate-with-amazon-opensearch-service)
6
6
  - [Using AWS V2 SDK](#using-aws-v2-sdk)
7
7
  - [Using AWS V3 SDK](#using-aws-v3-sdk)
8
- - [Enable Handling of Long Numerals](#enable-handling-of-long-numerals)
8
+ - [Enable Handling of Long Numerals](#enable-handling-of-long-numerals)
9
9
  - [Create an Index](#create-an-index)
10
10
  - [Add a Document to the Index](#add-a-document-to-the-index)
11
11
  - [Search for the Document](#search-for-the-document)
12
+ - [Multi-Search (msearch)](#multi-search-msearch)
12
13
  - [Delete the document](#delete-the-document)
13
14
  - [Delete the index](#delete-the-index)
15
+ - [Create a Point in Time](#create-a-point-in-time)
16
+ - [Get all PITs](#get-all-pits)
17
+ - [Delete a Point in Time](#delete-a-point-in-time)
18
+ - [Delete all PITs](#delete-all-pits)
14
19
  - [Empty all Pool Connections](#empty-all-pool-connections)
15
20
 
16
21
  ## Initializing a Client
@@ -94,8 +99,8 @@ const client = new Client({
94
99
  // Must return a Promise that resolve to an AWS.Credentials object.
95
100
  // This function is used to acquire the credentials when the client start and
96
101
  // when the credentials are expired.
97
- // The Client will refresh the Credentials only when they are expired.
98
- // With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials.
102
+ // The Client will treat the Credentials as expired if within
103
+ // `requestTimeout` ms of expiration (default is 30000 ms).
99
104
 
100
105
  // Example with AWS SDK V3:
101
106
  getCredentials: () => {
@@ -104,6 +109,7 @@ const client = new Client({
104
109
  return credentialsProvider();
105
110
  },
106
111
  }),
112
+ requestTimeout: 60000, // Also used for refreshing credentials in advance
107
113
  node: 'https://search-xxx.region.es.amazonaws.com', // OpenSearch domain URL
108
114
  // node: "https://xxx.region.aoss.amazonaws.com" for OpenSearch Serverless
109
115
  });
@@ -194,6 +200,30 @@ var response = await client.search({
194
200
  console.log(response.body.hits);
195
201
  ```
196
202
 
203
+ ## Multi-Search (msearch)
204
+
205
+ ```javascript
206
+ const queries = [
207
+ {},
208
+ { query: { match: { author: 'Stephen King' } } },
209
+ {},
210
+ { query: { match: { title: 'The Outsider' } } },
211
+ ];
212
+
213
+ const multiSearchResponse = await client.msearch({
214
+ index: index_name,
215
+ body: queries,
216
+ });
217
+
218
+ multiSearchResponse.body.responses.map((res) =>
219
+ res.hits.hits.map((movie) => {
220
+ console.log(movie._source);
221
+ })
222
+ );
223
+ ```
224
+
225
+ Explore `msearch` further with a detailed guide in [msearch.md](guides/msearch.md) and find sample code in [msearch.js](samples/msearch.js).
226
+
197
227
  ## Delete the document
198
228
 
199
229
  ```javascript
@@ -0,0 +1,213 @@
1
+ /*
2
+ * Copyright OpenSearch Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * The OpenSearch Contributors require contributions made to
6
+ * this file be licensed under the Apache-2.0 license or a
7
+ * compatible open source license.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /** @namespace API-HTTP */
14
+
15
+ const { normalizeArguments, kConfigurationError } = require('../utils');
16
+
17
+ function HttpApi(transport, ConfigurationError) {
18
+ this.transport = transport;
19
+ this[kConfigurationError] = ConfigurationError;
20
+ }
21
+
22
+ HttpApi.prototype.request = function (method, params, options, callback) {
23
+ [params, options, callback] = normalizeArguments(params, options, callback);
24
+ if (Array.isArray(params.body)) {
25
+ const { path, querystring, headers, body } = params;
26
+ params = { path, querystring, headers, bulkBody: body };
27
+ }
28
+ options = options || {};
29
+ options.headers = params.headers || options.headers;
30
+ return this.transport.request({ ...params, method }, options, callback);
31
+ };
32
+
33
+ /**
34
+ * Make a customized CONNECT request.
35
+ *
36
+ * @memberOf API-HTTP
37
+ *
38
+ * @param {Object} params
39
+ * @param {Object} params.path - The URL of the request
40
+ * @param {Object} [params.querystring] - The querystring parameters
41
+ * @param {Object} [params.headers] - The request headers
42
+ * @param {Object} [params.body] - The request body
43
+ *
44
+ * @param {Object} [options] - Options for {@link Transport#request}
45
+ * @param {function} [callback] - Callback that handles errors and response
46
+ *
47
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
48
+ */
49
+ HttpApi.prototype.connect = function (params, options, callback) {
50
+ return this.request('CONNECT', params, options, callback);
51
+ };
52
+
53
+ /**
54
+ * Make a customized DELETE request.
55
+ *
56
+ * @memberOf API-HTTP
57
+ *
58
+ * @param {Object} params
59
+ * @param {Object} params.path - The URL of the request
60
+ * @param {Object} [params.querystring] - The querystring parameters
61
+ * @param {Object} [params.headers] - The request headers
62
+ * @param {Object} [params.body] - The request body
63
+ *
64
+ * @param {Object} [options] - Options for {@link Transport#request}
65
+ * @param {function} [callback] - Callback that handles errors and response
66
+ *
67
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
68
+ */
69
+ HttpApi.prototype.delete = function (params, options, callback) {
70
+ return this.request('DELETE', params, options, callback);
71
+ };
72
+
73
+ /**
74
+ * Make a customized GET request.
75
+ *
76
+ * @memberOf API-HTTP
77
+ *
78
+ * @param {Object} params
79
+ * @param {Object} params.path - The URL of the request
80
+ * @param {Object} [params.querystring] - The querystring parameters
81
+ * @param {Object} [params.headers] - The request headers
82
+ * @param {Object} [params.body] - The request body
83
+ *
84
+ * @param {Object} [options] - Options for {@link Transport#request}
85
+ * @param {function} [callback] - Callback that handles errors and response
86
+ *
87
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
88
+ */
89
+ HttpApi.prototype.get = function (params, options, callback) {
90
+ return this.request('GET', params, options, callback);
91
+ };
92
+
93
+ /**
94
+ * Make a customized HEAD request.
95
+ *
96
+ * @memberOf API-HTTP
97
+ *
98
+ * @param {Object} params
99
+ * @param {Object} params.path - The URL of the request
100
+ * @param {Object} [params.querystring] - The querystring parameters
101
+ * @param {Object} [params.headers] - The request headers
102
+ * @param {Object} [params.body] - The request body
103
+ *
104
+ * @param {Object} [options] - Options for {@link Transport#request}
105
+ * @param {function} [callback] - Callback that handles errors and response
106
+ *
107
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
108
+ */
109
+ HttpApi.prototype.head = function (params, options, callback) {
110
+ return this.request('HEAD', params, options, callback);
111
+ };
112
+
113
+ /**
114
+ * Make a customized OPTIONS request.
115
+ *
116
+ * @memberOf API-HTTP
117
+ *
118
+ * @param {Object} params
119
+ * @param {Object} params.path - The URL of the request
120
+ * @param {Object} [params.querystring] - The querystring parameters
121
+ * @param {Object} [params.headers] - The request headers
122
+ * @param {Object} [params.body] - The request body
123
+ *
124
+ * @param {Object} [options] - Options for {@link Transport#request}
125
+ * @param {function} [callback] - Callback that handles errors and response
126
+ *
127
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
128
+ */
129
+ HttpApi.prototype.options = function (params, options, callback) {
130
+ return this.request('OPTIONS', params, options, callback);
131
+ };
132
+
133
+ /**
134
+ * Make a customized PATCH request.
135
+ *
136
+ * @memberOf API-HTTP
137
+ *
138
+ * @param {Object} params
139
+ * @param {Object} params.path - The URL of the request
140
+ * @param {Object} [params.querystring] - The querystring parameters
141
+ * @param {Object} [params.headers] - The request headers
142
+ * @param {Object} [params.body] - The request body
143
+ *
144
+ * @param {Object} [options] - Options for {@link Transport#request}
145
+ * @param {function} [callback] - Callback that handles errors and response
146
+ *
147
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
148
+ */
149
+ HttpApi.prototype.patch = function (params, options, callback) {
150
+ return this.request('PATCH', params, options, callback);
151
+ };
152
+
153
+ /**
154
+ * Make a customized POST request.
155
+ *
156
+ * @memberOf API-HTTP
157
+ *
158
+ * @param {Object} params
159
+ * @param {Object} params.path - The URL of the request
160
+ * @param {Object} [params.querystring] - The querystring parameters
161
+ * @param {Object} [params.headers] - The request headers
162
+ * @param {Object} [params.body] - The request body
163
+ *
164
+ * @param {Object} [options] - Options for {@link Transport#request}
165
+ * @param {function} [callback] - Callback that handles errors and response
166
+ *
167
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
168
+ */
169
+ HttpApi.prototype.post = function (params, options, callback) {
170
+ return this.request('POST', params, options, callback);
171
+ };
172
+
173
+ /**
174
+ * Make a customized PUT request.
175
+ *
176
+ * @memberOf API-HTTP
177
+ *
178
+ * @param {Object} params
179
+ * @param {Object} params.path - The URL of the request
180
+ * @param {Object} [params.querystring] - The querystring parameters
181
+ * @param {Object} [params.headers] - The request headers
182
+ * @param {Object} [params.body] - The request body
183
+ *
184
+ * @param {Object} [options] - Options for {@link Transport#request}
185
+ * @param {function} [callback] - Callback that handles errors and response
186
+ *
187
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
188
+ */
189
+ HttpApi.prototype.put = function (params, options, callback) {
190
+ return this.request('PUT', params, options, callback);
191
+ };
192
+
193
+ /**
194
+ * Make a customized TRACE request.
195
+ *
196
+ * @memberOf API-HTTP
197
+ *
198
+ * @param {Object} params
199
+ * @param {Object} params.path - The URL of the request
200
+ * @param {Object} [params.querystring] - The querystring parameters
201
+ * @param {Object} [params.headers] - The request headers
202
+ * @param {Object} [params.body] - The request body
203
+ *
204
+ * @param {Object} [options] - Options for {@link Transport#request}
205
+ * @param {function} [callback] - Callback that handles errors and response
206
+ *
207
+ * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
208
+ */
209
+ HttpApi.prototype.trace = function (params, options, callback) {
210
+ return this.request('TRACE', params, options, callback);
211
+ };
212
+
213
+ module.exports = HttpApi;
@@ -1336,7 +1336,7 @@ IndicesApi.prototype.getTemplate = function indicesGetTemplateApi(params, option
1336
1336
  };
1337
1337
 
1338
1338
  /**
1339
- * Returns a progress status of current upgrade. (Deprecated. Use API-Document#reindex instead)
1339
+ * Returns a progress status of current upgrade.
1340
1340
  *
1341
1341
  * @memberOf API-Index
1342
1342
  *
package/api/index.js CHANGED
@@ -54,6 +54,7 @@ const getScriptApi = require('./api/get_script');
54
54
  const getScriptContextApi = require('./api/get_script_context');
55
55
  const getScriptLanguagesApi = require('./api/get_script_languages');
56
56
  const getSourceApi = require('./api/get_source');
57
+ const HttpApi = require('./api/http');
57
58
  const indexApi = require('./api/index');
58
59
  const IndicesApi = require('./api/indices');
59
60
  const infoApi = require('./api/info');
@@ -89,6 +90,7 @@ const kCat = Symbol('Cat');
89
90
  const kCluster = Symbol('Cluster');
90
91
  const kDanglingIndices = Symbol('DanglingIndices');
91
92
  const kFeatures = Symbol('Features');
93
+ const kHttp = Symbol('Http');
92
94
  const kIndices = Symbol('Indices');
93
95
  const kIngest = Symbol('Ingest');
94
96
  const kNodes = Symbol('Nodes');
@@ -103,6 +105,7 @@ function OpenSearchAPI(opts) {
103
105
  this[kCluster] = null;
104
106
  this[kDanglingIndices] = null;
105
107
  this[kFeatures] = null;
108
+ this[kHttp] = null;
106
109
  this[kIndices] = null;
107
110
  this[kIngest] = null;
108
111
  this[kNodes] = null;
@@ -264,6 +267,14 @@ Object.defineProperties(OpenSearchAPI.prototype, {
264
267
  return this.getSource;
265
268
  },
266
269
  },
270
+ http: {
271
+ get() {
272
+ if (this[kHttp] === null) {
273
+ this[kHttp] = new HttpApi(this.transport, this[kConfigurationError]);
274
+ }
275
+ return this[kHttp];
276
+ },
277
+ },
267
278
  indices: {
268
279
  get() {
269
280
  if (this[kIndices] === null) {
package/api/new.d.ts CHANGED
@@ -951,14 +951,17 @@ declare class Client {
951
951
  options: TransportRequestOptions,
952
952
  callback: callbackFn<T.IndicesDeleteIndexTemplateResponse, TContext>
953
953
  ): TransportRequestCallback;
954
+ /** @deprecated use deleteIndexTemplate instead */
954
955
  deleteTemplate<TContext = unknown>(
955
956
  params: T.IndicesDeleteTemplateRequest,
956
957
  options?: TransportRequestOptions
957
958
  ): TransportRequestPromise<ApiResponse<T.IndicesDeleteTemplateResponse, TContext>>;
959
+ /** @deprecated use deleteIndexTemplate instead */
958
960
  deleteTemplate<TContext = unknown>(
959
961
  params: T.IndicesDeleteTemplateRequest,
960
962
  callback: callbackFn<T.IndicesDeleteTemplateResponse, TContext>
961
963
  ): TransportRequestCallback;
964
+ /** @deprecated use deleteIndexTemplate instead */
962
965
  deleteTemplate<TContext = unknown>(
963
966
  params: T.IndicesDeleteTemplateRequest,
964
967
  options: TransportRequestOptions,
@@ -1017,14 +1020,17 @@ declare class Client {
1017
1020
  options: TransportRequestOptions,
1018
1021
  callback: callbackFn<T.IndicesExistsIndexTemplateResponse, TContext>
1019
1022
  ): TransportRequestCallback;
1023
+ /** @deprecated use existsIndexTemplate instead */
1020
1024
  existsTemplate<TContext = unknown>(
1021
1025
  params: T.IndicesExistsTemplateRequest,
1022
1026
  options?: TransportRequestOptions
1023
1027
  ): TransportRequestPromise<ApiResponse<T.IndicesExistsTemplateResponse, TContext>>;
1028
+ /** @deprecated use existsIndexTemplate instead */
1024
1029
  existsTemplate<TContext = unknown>(
1025
1030
  params: T.IndicesExistsTemplateRequest,
1026
1031
  callback: callbackFn<T.IndicesExistsTemplateResponse, TContext>
1027
1032
  ): TransportRequestCallback;
1033
+ /** @deprecated use existsIndexTemplate instead */
1028
1034
  existsTemplate<TContext = unknown>(
1029
1035
  params: T.IndicesExistsTemplateRequest,
1030
1036
  options: TransportRequestOptions,
@@ -1168,17 +1174,21 @@ declare class Client {
1168
1174
  options: TransportRequestOptions,
1169
1175
  callback: callbackFn<T.IndicesGetSettingsResponse, TContext>
1170
1176
  ): TransportRequestCallback;
1177
+ /** @deprecated use getIndexTemplate instead */
1171
1178
  getTemplate<TContext = unknown>(
1172
1179
  params?: T.IndicesGetTemplateRequest,
1173
1180
  options?: TransportRequestOptions
1174
1181
  ): TransportRequestPromise<ApiResponse<T.IndicesGetTemplateResponse, TContext>>;
1182
+ /** @deprecated use getIndexTemplate instead */
1175
1183
  getTemplate<TContext = unknown>(
1176
1184
  callback: callbackFn<T.IndicesGetTemplateResponse, TContext>
1177
1185
  ): TransportRequestCallback;
1186
+ /** @deprecated use getIndexTemplate instead */
1178
1187
  getTemplate<TContext = unknown>(
1179
1188
  params: T.IndicesGetTemplateRequest,
1180
1189
  callback: callbackFn<T.IndicesGetTemplateResponse, TContext>
1181
1190
  ): TransportRequestCallback;
1191
+ /** @deprecated use getIndexTemplate instead */
1182
1192
  getTemplate<TContext = unknown>(
1183
1193
  params: T.IndicesGetTemplateRequest,
1184
1194
  options: TransportRequestOptions,
@@ -1269,14 +1279,17 @@ declare class Client {
1269
1279
  options: TransportRequestOptions,
1270
1280
  callback: callbackFn<T.IndicesPutSettingsResponse, TContext>
1271
1281
  ): TransportRequestCallback;
1282
+ /** @deprecated use putIndexTemplate instead */
1272
1283
  putTemplate<TContext = unknown>(
1273
1284
  params: T.IndicesPutTemplateRequest,
1274
1285
  options?: TransportRequestOptions
1275
1286
  ): TransportRequestPromise<ApiResponse<T.IndicesPutTemplateResponse, TContext>>;
1287
+ /** @deprecated use putIndexTemplate instead */
1276
1288
  putTemplate<TContext = unknown>(
1277
1289
  params: T.IndicesPutTemplateRequest,
1278
1290
  callback: callbackFn<T.IndicesPutTemplateResponse, TContext>
1279
1291
  ): TransportRequestCallback;
1292
+ /** @deprecated use putIndexTemplate instead */
1280
1293
  putTemplate<TContext = unknown>(
1281
1294
  params: T.IndicesPutTemplateRequest,
1282
1295
  options: TransportRequestOptions,
@@ -1401,17 +1414,21 @@ declare class Client {
1401
1414
  options: TransportRequestOptions,
1402
1415
  callback: callbackFn<T.IndicesSimulateIndexTemplateResponse, TContext>
1403
1416
  ): TransportRequestCallback;
1417
+ /** @deprecated use simulateIndexTemplate instead */
1404
1418
  simulateTemplate<TContext = unknown>(
1405
1419
  params?: TODO,
1406
1420
  options?: TransportRequestOptions
1407
1421
  ): TransportRequestPromise<ApiResponse<TODO, TContext>>;
1422
+ /** @deprecated use simulateIndexTemplate instead */
1408
1423
  simulateTemplate<TContext = unknown>(
1409
1424
  callback: callbackFn<TODO, TContext>
1410
1425
  ): TransportRequestCallback;
1426
+ /** @deprecated use simulateIndexTemplate instead */
1411
1427
  simulateTemplate<TContext = unknown>(
1412
1428
  params: TODO,
1413
1429
  callback: callbackFn<TODO, TContext>
1414
1430
  ): TransportRequestCallback;
1431
+ /** @deprecated use simulateIndexTemplate instead */
1415
1432
  simulateTemplate<TContext = unknown>(
1416
1433
  params: TODO,
1417
1434
  options: TransportRequestOptions,
@@ -750,6 +750,13 @@ export interface GetSource extends Generic {
750
750
  version_type?: 'internal' | 'external' | 'external_gte' | 'force';
751
751
  }
752
752
 
753
+ export interface HttpParams extends Generic {
754
+ path: string;
755
+ querystring?: Record<string, any>;
756
+ headers?: Record<string, any>;
757
+ body?: Record<string, any> | string | Array<string | Record<string, any>>;
758
+ }
759
+
753
760
  export interface Index<T = RequestBody> extends Generic {
754
761
  id?: string;
755
762
  index: string;
@@ -139,9 +139,9 @@ client.indices.delete({index: 'movies'})
139
139
  We can also delete multiple indices at once:
140
140
 
141
141
  ```javascript
142
- client.indices.delete({index: ['movies', 'paintings', 'burner'], ignore: 404})
142
+ client.indices.delete({index: ['movies', 'paintings', 'burner'], ignore_unavailable: true,})
143
143
  ```
144
- Notice that we are passing `ignore: 404` to the request. This tells the client to ignore the `404` error if the index doesn't exist for deletion. Without it, the above `delete` request will throw an error because the `movies` index has already been deleted in the previous example.
144
+ Notice that we are passing `ignore_unavailable: true` to the request. This tells the client to ignore throwing error and deleting the index if it doesn't exist. Without it, the above `delete` request will throw an error because the `movies` index has already been deleted in the previous example.
145
145
 
146
146
  ## Cleanup
147
147
 
package/guides/json.md ADDED
@@ -0,0 +1,60 @@
1
+ # Making raw HTTP requests
2
+
3
+ The OpenSearch client implements many high-level REST DSLs that invoke OpenSearch APIs. However, you may find yourself in a situation that requires you to invoke an API that is not supported by the client. In this case, you can use raw HTTP requests to invoke any OpenSearch API. This guide shows you different ways to make custom API calls using the OpenSearch JS client.
4
+
5
+ ## Setup
6
+ First, create a client instance with the following code to interact with an OpenSearch cluster with default security settings:
7
+
8
+ ```javascript
9
+ const client = new Client({
10
+ ssl: {
11
+ rejectUnauthorized: false,
12
+ },
13
+ node: 'https://localhost:9200',
14
+ auth: {
15
+ username: 'admin',
16
+ password: 'admin',
17
+ },
18
+ });
19
+ ```
20
+
21
+ ## The http Namespace
22
+ The `http` namespace comes with all functions representing HTTP methods like `connect`, `delete`, `get`, `head`, `options`, `patch`, `post`, `put`, and `trace`.
23
+
24
+ Let's create in index using `http.put`:
25
+ ```javascript
26
+ await client.http.put({
27
+ path: '/movies',
28
+ body: {
29
+ mappings: {
30
+ properties: {
31
+ title: { type: 'text' },
32
+ director: { type: 'text' },
33
+ year: { type: 'integer' },
34
+ },
35
+ },
36
+ },
37
+ });
38
+ ```
39
+
40
+ Make sure that the index was created successfully using `http.head`:
41
+
42
+ ```javascript
43
+ await client.http.head({ path: '/movies' });
44
+ ```
45
+
46
+ Add two documents to the index using `http.post` and the bulk endpoint
47
+ ```javascript
48
+ const body = [
49
+ { index: { _index: index } },
50
+ { title: 'The quick brown fox' },
51
+ { index: { _index: index } },
52
+ { title: 'The quick brown fox jumps over the lazy dog' },
53
+ ];
54
+ await client.http.post({ path: `_bulk`, body });
55
+ ```
56
+
57
+ Delete the index using `http.delete`:
58
+ ```javascript
59
+ await client.http.delete({ path: '/movies' });
60
+ ```
@@ -0,0 +1,66 @@
1
+ # Multi-Search (msearch)
2
+
3
+ OpenSearch's Multi-Search (`msearch`) API allows you to execute multiple search operations for documents within an index efficiently. This API supports various parameters that provide flexibility in customizing your search operations. It's crucial to understand the key differences between `msearch` and a regular `search` operation in OpenSearch. Unlike a single search operation, `msearch` enables you to perform multiple searches in a single API call, significantly reducing network overhead as it need not initialize a new network connection for each search. This proves particularly advantageous for batch operations or scenarios where searches span multiple indices. By combining searches into one request, `msearch` streamlines the process and enhances overall efficiency. However, it's important to note that there will also be a bit more memory overhead in the `msearch`, as the coordinating node will have to accumulate the various search responses in memory before sending back the final response. Explore the functionalities of the msearch API with the provided sample code in [../samples/msearch.js](../samples/msearch.js).
4
+
5
+ # Setup
6
+
7
+ ```javascript
8
+ const host = "localhost";
9
+ const protocol = "https";
10
+ const port = 9200;
11
+ const auth = "admin:admin";
12
+ const ca_certs_path = "/full/path/to/root-ca.pem";
13
+ const { Client } = require("@opensearch-project/opensearch");
14
+ const fs = require("fs");
15
+ const client = new Client({
16
+ node: `${protocol}://${auth}@${host}:${port}`,
17
+ ssl: {
18
+ ca: fs.readFileSync(ca_certs_path),
19
+ },
20
+ });
21
+
22
+ await client.bulk({
23
+ body: [
24
+ { index: { _index: 'movies', _id: 1 } },
25
+ { title: 'The Godfather', director: 'Francis Ford Coppola', year: 1972 },
26
+ { index: { _index: 'movies', _id: 2 } },
27
+ { title: 'The Godfather: Part II', director: 'Francis Ford Coppola', year: 1974 },
28
+ ],
29
+ });
30
+
31
+ await client.index.refresh({ index: 'movies' });
32
+ ```
33
+
34
+ # Multi Search API
35
+
36
+ The multi-search allows you to execute multiple search requests within a single API call. The following example shows how each search query provides a list of documents from the movie index.
37
+
38
+ ```javascript
39
+ try {
40
+ const queries = [
41
+ {},
42
+ { query: { match: { title: 'The Godfather' } } },
43
+ {},
44
+ { query: { match: { title: 'Part II' } } },
45
+ ];
46
+
47
+ const multiSearchResponse = await client.msearch({
48
+ index: 'movies',
49
+ body: queries,
50
+ });
51
+
52
+ multiSearchResponse.body.responses.map((res) =>
53
+ res.hits.hits.map((movie) => {
54
+ console.log(movie._source);
55
+ })
56
+ );
57
+ } catch (error) {
58
+ console.error('An error occurred:', error);
59
+ }
60
+ ```
61
+
62
+ # Cleanup
63
+
64
+ ```javascript
65
+ await client.indices.delete({index: 'movies'});
66
+ ```
package/guides/search.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Search
2
- OpenSearch provides a powerful search API that allows you to search for documents in an index. The search API supports a number of parameters that allow you to customize the search operation. In this guide, we will explore the search API and its parameters.
2
+ OpenSearch provides a powerful search API that allows you to search for documents in an index. The search API supports a number of parameters that allow you to customize the search operation. In this guide, we will explore the search API and its parameters. To complement your exploration of the OpenSearch Search API and its parameters, a working sample is available in [`../samples/search.js`](../samples/search.js).
3
3
  # Setup
4
4
  Let's start by creating an index and adding some documents to it:
5
5
  ```javascript