@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.
- package/.eslintignore +2 -0
- package/.eslintrc.json +31 -0
- package/.prettierrc.json +5 -0
- package/.whitesource +15 -0
- package/ADMINS.md +13 -31
- package/CHANGELOG.md +24 -0
- package/COMPATIBILITY.md +27 -0
- package/DEVELOPER_GUIDE.md +22 -5
- package/MAINTAINERS.md +15 -70
- package/Makefile +2 -12
- package/README.md +19 -123
- package/RELEASING.md +3 -3
- package/SECURITY.md +1 -1
- package/USER_GUIDE.md +197 -0
- package/api/api/bulk.js +54 -28
- package/api/api/cat.js +355 -266
- package/api/api/clear_scroll.js +18 -19
- package/api/api/cluster.js +367 -221
- package/api/api/count.js +56 -26
- package/api/api/create.js +51 -26
- package/api/api/dangling_indices.js +96 -53
- package/api/api/delete.js +50 -24
- package/api/api/delete_by_query.js +89 -27
- package/api/api/delete_by_query_rethrottle.js +34 -21
- package/api/api/delete_script.js +32 -19
- package/api/api/exists.js +56 -24
- package/api/api/exists_source.js +61 -29
- package/api/api/explain.js +61 -24
- package/api/api/features.js +57 -37
- package/api/api/field_caps.js +37 -20
- package/api/api/get.js +56 -24
- package/api/api/get_script.js +31 -19
- package/api/api/get_script_context.js +16 -17
- package/api/api/get_script_languages.js +16 -17
- package/api/api/get_source.js +56 -24
- package/api/api/index.js +61 -30
- package/api/api/indices.js +1069 -859
- package/api/api/info.js +16 -17
- package/api/api/ingest.js +133 -98
- package/api/api/mget.js +51 -28
- package/api/api/msearch.js +50 -28
- package/api/api/msearch_template.js +54 -28
- package/api/api/mtermvectors.js +49 -26
- package/api/api/nodes.js +282 -156
- package/api/api/ping.js +16 -17
- package/api/api/put_script.js +41 -27
- package/api/api/rank_eval.js +38 -22
- package/api/api/reindex.js +39 -19
- package/api/api/reindex_rethrottle.js +33 -21
- package/api/api/render_search_template.js +19 -20
- package/api/api/scripts_painless_execute.js +16 -17
- package/api/api/scroll.js +32 -19
- package/api/api/search.js +109 -26
- package/api/api/search_shards.js +37 -20
- package/api/api/search_template.js +65 -28
- package/api/api/shutdown.js +67 -56
- package/api/api/snapshot.js +348 -226
- package/api/api/tasks.js +66 -48
- package/api/api/terms_enum.js +18 -19
- package/api/api/termvectors.js +58 -28
- package/api/api/update.js +65 -26
- package/api/api/update_by_query.js +90 -25
- package/api/api/update_by_query_rethrottle.js +34 -21
- package/api/index.js +268 -181
- package/api/new.d.ts +2043 -531
- package/api/opensearch_dashboards.d.ts +240 -238
- package/api/requestParams.d.ts +302 -71
- package/api/types.d.ts +6205 -5721
- package/api/utils.js +23 -24
- package/codecov.yml +2 -2
- package/index.d.ts +5203 -1037
- package/index.js +154 -143
- package/index.mjs +10 -11
- package/jenkins/release.JenkinsFile +11 -0
- package/lib/Connection.d.ts +38 -28
- package/lib/Connection.js +166 -170
- package/lib/Helpers.d.ts +108 -68
- package/lib/Helpers.js +401 -378
- package/lib/Serializer.d.ts +3 -4
- package/lib/Serializer.js +40 -41
- package/lib/Transport.d.ts +39 -15
- package/lib/Transport.js +381 -337
- package/lib/aws/AwsSigv4Signer.js +167 -0
- package/lib/aws/errors.js +24 -0
- package/lib/aws/index.d.ts +39 -0
- package/lib/aws/index.js +19 -0
- package/lib/errors.d.ts +26 -9
- package/lib/errors.js +76 -73
- package/lib/pool/BaseConnectionPool.js +101 -99
- package/lib/pool/CloudConnectionPool.js +17 -18
- package/lib/pool/ConnectionPool.js +106 -107
- package/lib/pool/index.d.ts +9 -8
- package/lib/pool/index.js +7 -8
- package/package.json +37 -15
package/USER_GUIDE.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# User Guide
|
|
2
|
+
|
|
3
|
+
- [User Guide](#user-guide)
|
|
4
|
+
- [Initializing a Client](#initializing-a-client)
|
|
5
|
+
- [Authenticate with Amazon OpenSearch Service](#authenticate-with-amazon-opensearch-service)
|
|
6
|
+
- [Using AWS V2 SDK](#using-aws-v2-sdk)
|
|
7
|
+
- [Using AWS V3 SDK](#using-aws-v3-sdk)
|
|
8
|
+
- [Create an Index](#create-an-index)
|
|
9
|
+
- [Add a Document to the Index](#add-a-document-to-the-index)
|
|
10
|
+
- [Search for the Document](#search-for-the-document)
|
|
11
|
+
- [Delete the document](#delete-the-document)
|
|
12
|
+
- [Delete the index](#delete-the-index)
|
|
13
|
+
|
|
14
|
+
## Initializing a Client
|
|
15
|
+
```javascript
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
var host = 'localhost';
|
|
19
|
+
var protocol = 'https';
|
|
20
|
+
var port = 9200;
|
|
21
|
+
var auth = 'admin:admin'; // For testing only. Don't store credentials in code.
|
|
22
|
+
var ca_certs_path = '/full/path/to/root-ca.pem';
|
|
23
|
+
|
|
24
|
+
// Optional client certificates if you don't want to use HTTP basic authentication.
|
|
25
|
+
// var client_cert_path = '/full/path/to/client.pem'
|
|
26
|
+
// var client_key_path = '/full/path/to/client-key.pem'
|
|
27
|
+
|
|
28
|
+
// Create a client with SSL/TLS enabled.
|
|
29
|
+
var { Client } = require('@opensearch-project/opensearch');
|
|
30
|
+
var fs = require('fs');
|
|
31
|
+
var client = new Client({
|
|
32
|
+
node: protocol + '://' + auth + '@' + host + ':' + port,
|
|
33
|
+
ssl: {
|
|
34
|
+
ca: fs.readFileSync(ca_certs_path),
|
|
35
|
+
// You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch.
|
|
36
|
+
// cert: fs.readFileSync(client_cert_path),
|
|
37
|
+
// key: fs.readFileSync(client_key_path)
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Authenticate with Amazon OpenSearch Service
|
|
43
|
+
|
|
44
|
+
#### Using AWS V2 SDK
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const AWS = require('aws-sdk'); // V2 SDK.
|
|
48
|
+
const { Client } = require('@opensearch-project/opensearch');
|
|
49
|
+
const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws');
|
|
50
|
+
|
|
51
|
+
const client = new Client({
|
|
52
|
+
...AwsSigv4Signer({
|
|
53
|
+
region: 'us-east-1',
|
|
54
|
+
// Must return a Promise that resolve to an AWS.Credentials object.
|
|
55
|
+
// This function is used to acquire the credentials when the client start and
|
|
56
|
+
// when the credentials are expired.
|
|
57
|
+
// The Client will refresh the Credentials only when they are expired.
|
|
58
|
+
// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials.
|
|
59
|
+
|
|
60
|
+
// Example with AWS SDK V2:
|
|
61
|
+
getCredentials: () =>
|
|
62
|
+
new Promise((resolve, reject) => {
|
|
63
|
+
// Any other method to acquire a new Credentials object can be used.
|
|
64
|
+
AWS.config.getCredentials((err, credentials) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
reject(err);
|
|
67
|
+
} else {
|
|
68
|
+
resolve(credentials);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}),
|
|
72
|
+
}),
|
|
73
|
+
node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Using AWS V3 SDK
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const { defaultProvider } = require("@aws-sdk/credential-provider-node"); // V3 SDK.
|
|
81
|
+
const { Client } = require('@opensearch-project/opensearch');
|
|
82
|
+
const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws');
|
|
83
|
+
|
|
84
|
+
const client = new Client({
|
|
85
|
+
...AwsSigv4Signer({
|
|
86
|
+
region: 'us-east-1',
|
|
87
|
+
// Must return a Promise that resolve to an AWS.Credentials object.
|
|
88
|
+
// This function is used to acquire the credentials when the client start and
|
|
89
|
+
// when the credentials are expired.
|
|
90
|
+
// The Client will refresh the Credentials only when they are expired.
|
|
91
|
+
// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials.
|
|
92
|
+
|
|
93
|
+
// Example with AWS SDK V3:
|
|
94
|
+
getCredentials: () => {
|
|
95
|
+
// Any other method to acquire a new Credentials object can be used.
|
|
96
|
+
const credentialsProvider = defaultProvider();
|
|
97
|
+
return credentialsProvider();
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Create an Index
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
console.log('Creating index:');
|
|
108
|
+
|
|
109
|
+
var index_name = 'books';
|
|
110
|
+
var settings = {
|
|
111
|
+
settings: {
|
|
112
|
+
index: {
|
|
113
|
+
number_of_shards: 4,
|
|
114
|
+
number_of_replicas: 3,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
var response = await client.indices.create({
|
|
120
|
+
index: index_name,
|
|
121
|
+
body: settings,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
console.log(response.body);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Add a Document to the Index
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
console.log('Adding document:');
|
|
131
|
+
|
|
132
|
+
var document = {
|
|
133
|
+
title: 'The Outsider',
|
|
134
|
+
author: 'Stephen King',
|
|
135
|
+
year: '2018',
|
|
136
|
+
genre: 'Crime fiction',
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
var id = '1';
|
|
140
|
+
|
|
141
|
+
var response = await client.index({
|
|
142
|
+
id: id,
|
|
143
|
+
index: index_name,
|
|
144
|
+
body: document,
|
|
145
|
+
refresh: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(response.body);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Search for the Document
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
console.log('Search results:');
|
|
155
|
+
|
|
156
|
+
var query = {
|
|
157
|
+
query: {
|
|
158
|
+
match: {
|
|
159
|
+
title: {
|
|
160
|
+
query: 'The Outsider',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
var response = await client.search({
|
|
167
|
+
index: index_name,
|
|
168
|
+
body: query,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
console.log(response.body.hits);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Delete the document
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
console.log('Deleting document:');
|
|
178
|
+
|
|
179
|
+
var response = await client.delete({
|
|
180
|
+
index: index_name,
|
|
181
|
+
id: id,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
console.log(response.body);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Delete the index
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
console.log('Deleting index:');
|
|
191
|
+
|
|
192
|
+
var response = await client.indices.delete({
|
|
193
|
+
index: index_name,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
console.log(response.body);
|
|
197
|
+
```
|
package/api/api/bulk.js
CHANGED
|
@@ -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,43 +27,70 @@
|
|
|
28
27
|
* under the License.
|
|
29
28
|
*/
|
|
30
29
|
|
|
31
|
-
'use strict'
|
|
30
|
+
'use strict';
|
|
32
31
|
|
|
33
32
|
/* eslint camelcase: 0 */
|
|
34
33
|
/* eslint no-unused-vars: 0 */
|
|
35
34
|
|
|
36
|
-
const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils')
|
|
37
|
-
const acceptedQuerystring = [
|
|
38
|
-
|
|
35
|
+
const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
|
|
36
|
+
const acceptedQuerystring = [
|
|
37
|
+
'wait_for_active_shards',
|
|
38
|
+
'refresh',
|
|
39
|
+
'routing',
|
|
40
|
+
'timeout',
|
|
41
|
+
'type',
|
|
42
|
+
'_source',
|
|
43
|
+
'_source_excludes',
|
|
44
|
+
'_source_exclude',
|
|
45
|
+
'_source_includes',
|
|
46
|
+
'_source_include',
|
|
47
|
+
'pipeline',
|
|
48
|
+
'require_alias',
|
|
49
|
+
'pretty',
|
|
50
|
+
'human',
|
|
51
|
+
'error_trace',
|
|
52
|
+
'source',
|
|
53
|
+
'filter_path',
|
|
54
|
+
];
|
|
55
|
+
const snakeCase = {
|
|
56
|
+
waitForActiveShards: 'wait_for_active_shards',
|
|
57
|
+
_sourceExcludes: '_source_excludes',
|
|
58
|
+
_sourceExclude: '_source_exclude',
|
|
59
|
+
_sourceIncludes: '_source_includes',
|
|
60
|
+
_sourceInclude: '_source_include',
|
|
61
|
+
requireAlias: 'require_alias',
|
|
62
|
+
errorTrace: 'error_trace',
|
|
63
|
+
filterPath: 'filter_path',
|
|
64
|
+
};
|
|
39
65
|
|
|
40
|
-
function bulkApi
|
|
41
|
-
|
|
66
|
+
function bulkApi(params, options, callback) {
|
|
67
|
+
[params, options, callback] = normalizeArguments(params, options, callback);
|
|
42
68
|
|
|
43
69
|
// check required parameters
|
|
44
70
|
if (params.body == null) {
|
|
45
|
-
const err = new this[kConfigurationError]('Missing required parameter: body')
|
|
46
|
-
return handleError(err, callback)
|
|
71
|
+
const err = new this[kConfigurationError]('Missing required parameter: body');
|
|
72
|
+
return handleError(err, callback);
|
|
47
73
|
}
|
|
48
74
|
|
|
49
75
|
// check required url components
|
|
50
|
-
if (params.type != null &&
|
|
51
|
-
const err = new this[kConfigurationError]('Missing required parameter of the url: index')
|
|
52
|
-
return handleError(err, callback)
|
|
76
|
+
if (params.type != null && params.index == null) {
|
|
77
|
+
const err = new this[kConfigurationError]('Missing required parameter of the url: index');
|
|
78
|
+
return handleError(err, callback);
|
|
53
79
|
}
|
|
54
80
|
|
|
55
|
-
let { method, body, index, type, ...querystring } = params
|
|
56
|
-
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring)
|
|
81
|
+
let { method, body, index, type, ...querystring } = params;
|
|
82
|
+
querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
|
|
57
83
|
|
|
58
|
-
let path = ''
|
|
59
|
-
if (
|
|
60
|
-
if (method == null) method = 'POST'
|
|
61
|
-
path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + '_bulk'
|
|
62
|
-
} else if (
|
|
63
|
-
if (method == null) method = 'POST'
|
|
64
|
-
path = '/' + encodeURIComponent(index) + '/' + '_bulk'
|
|
84
|
+
let path = '';
|
|
85
|
+
if (index != null && type != null) {
|
|
86
|
+
if (method == null) method = 'POST';
|
|
87
|
+
path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + '_bulk';
|
|
88
|
+
} else if (index != null) {
|
|
89
|
+
if (method == null) method = 'POST';
|
|
90
|
+
path = '/' + encodeURIComponent(index) + '/' + '_bulk';
|
|
65
91
|
} else {
|
|
66
|
-
if (method == null) method = 'POST'
|
|
67
|
-
path = '/' + '_bulk'
|
|
92
|
+
if (method == null) method = 'POST';
|
|
93
|
+
path = '/' + '_bulk';
|
|
68
94
|
}
|
|
69
95
|
|
|
70
96
|
// build request object
|
|
@@ -72,10 +98,10 @@ function bulkApi (params, options, callback) {
|
|
|
72
98
|
method,
|
|
73
99
|
path,
|
|
74
100
|
bulkBody: body,
|
|
75
|
-
querystring
|
|
76
|
-
}
|
|
101
|
+
querystring,
|
|
102
|
+
};
|
|
77
103
|
|
|
78
|
-
return this.transport.request(request, options, callback)
|
|
104
|
+
return this.transport.request(request, options, callback);
|
|
79
105
|
}
|
|
80
106
|
|
|
81
|
-
module.exports = bulkApi
|
|
107
|
+
module.exports = bulkApi;
|