@opensearch-project/opensearch 2.0.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 (87) hide show
  1. package/.eslintrc.json +9 -4
  2. package/ADMINS.md +13 -38
  3. package/CHANGELOG.md +24 -0
  4. package/COMPATIBILITY.md +4 -1
  5. package/MAINTAINERS.md +15 -75
  6. package/Makefile +2 -12
  7. package/README.md +4 -107
  8. package/USER_GUIDE.md +197 -0
  9. package/api/api/bulk.js +1 -2
  10. package/api/api/cat.js +1 -2
  11. package/api/api/clear_scroll.js +1 -2
  12. package/api/api/cluster.js +1 -2
  13. package/api/api/count.js +1 -2
  14. package/api/api/create.js +1 -2
  15. package/api/api/dangling_indices.js +1 -2
  16. package/api/api/delete.js +1 -2
  17. package/api/api/delete_by_query.js +1 -2
  18. package/api/api/delete_by_query_rethrottle.js +1 -2
  19. package/api/api/delete_script.js +1 -2
  20. package/api/api/exists.js +1 -2
  21. package/api/api/exists_source.js +1 -2
  22. package/api/api/explain.js +1 -2
  23. package/api/api/features.js +1 -2
  24. package/api/api/field_caps.js +1 -2
  25. package/api/api/get.js +1 -2
  26. package/api/api/get_script.js +1 -2
  27. package/api/api/get_script_context.js +1 -2
  28. package/api/api/get_script_languages.js +1 -2
  29. package/api/api/get_source.js +1 -2
  30. package/api/api/index.js +1 -2
  31. package/api/api/indices.js +1 -2
  32. package/api/api/info.js +1 -2
  33. package/api/api/ingest.js +1 -2
  34. package/api/api/mget.js +1 -2
  35. package/api/api/msearch.js +1 -2
  36. package/api/api/msearch_template.js +1 -2
  37. package/api/api/mtermvectors.js +1 -2
  38. package/api/api/nodes.js +1 -2
  39. package/api/api/ping.js +1 -2
  40. package/api/api/put_script.js +1 -2
  41. package/api/api/rank_eval.js +1 -2
  42. package/api/api/reindex.js +1 -2
  43. package/api/api/reindex_rethrottle.js +1 -2
  44. package/api/api/render_search_template.js +1 -2
  45. package/api/api/scripts_painless_execute.js +1 -2
  46. package/api/api/scroll.js +1 -2
  47. package/api/api/search.js +1 -2
  48. package/api/api/search_shards.js +1 -2
  49. package/api/api/search_template.js +1 -2
  50. package/api/api/shutdown.js +1 -2
  51. package/api/api/snapshot.js +1 -2
  52. package/api/api/tasks.js +1 -2
  53. package/api/api/terms_enum.js +1 -2
  54. package/api/api/termvectors.js +1 -2
  55. package/api/api/update.js +1 -2
  56. package/api/api/update_by_query.js +1 -2
  57. package/api/api/update_by_query_rethrottle.js +1 -2
  58. package/api/index.js +1 -2
  59. package/api/new.d.ts +1 -2
  60. package/api/opensearch_dashboards.d.ts +1 -2
  61. package/api/requestParams.d.ts +1 -2
  62. package/api/types.d.ts +1 -2
  63. package/api/utils.js +1 -2
  64. package/index.d.ts +445 -120
  65. package/index.js +2 -3
  66. package/index.mjs +1 -2
  67. package/jenkins/release.JenkinsFile +11 -0
  68. package/lib/Connection.d.ts +1 -2
  69. package/lib/Connection.js +5 -4
  70. package/lib/Helpers.d.ts +5 -4
  71. package/lib/Helpers.js +13 -17
  72. package/lib/Serializer.d.ts +1 -2
  73. package/lib/Serializer.js +1 -2
  74. package/lib/Transport.d.ts +10 -4
  75. package/lib/Transport.js +11 -6
  76. package/lib/aws/AwsSigv4Signer.js +167 -0
  77. package/lib/aws/errors.js +24 -0
  78. package/lib/aws/index.d.ts +39 -0
  79. package/lib/aws/index.js +19 -0
  80. package/lib/errors.d.ts +1 -2
  81. package/lib/errors.js +1 -2
  82. package/lib/pool/BaseConnectionPool.js +1 -2
  83. package/lib/pool/CloudConnectionPool.js +1 -2
  84. package/lib/pool/ConnectionPool.js +1 -2
  85. package/lib/pool/index.d.ts +1 -2
  86. package/lib/pool/index.js +1 -2
  87. package/package.json +27 -10
package/.eslintrc.json CHANGED
@@ -18,9 +18,14 @@
18
18
  "endOfLine": "auto"
19
19
  }
20
20
  ],
21
- /*temporarily turn off no-unused-vars, open an issue to track https://github.com/opensearch-project/opensearch-js/issues/241*/
22
- "no-unused-vars": "off",
23
21
  /*temporarily turn off no-dupe-else-if, open an issue to track https://github.com/opensearch-project/opensearch-js/issues/240*/
24
- "no-dupe-else-if": "off"
22
+ "no-dupe-else-if": "off",
23
+ "no-unused-vars": [
24
+ "error",
25
+ {
26
+ "varsIgnorePattern": "^_.*",
27
+ "argsIgnorePattern": "^_.*"
28
+ }
29
+ ]
25
30
  }
26
- }
31
+ }
package/ADMINS.md CHANGED
@@ -1,41 +1,16 @@
1
- - [Overview](#overview)
2
- - [Current Admins](#current-admins)
3
- - [Admin Responsibilities](#admin-responsibilities)
4
- - [Prioritize Security](#prioritize-security)
5
- - [Enforce Code of Conduct](#enforce-code-of-conduct)
6
- - [Adopt Organizational Best Practices](#adopt-organizational-best-practices)
7
-
8
- ## Overview
9
-
10
- This document explains who the admins are (see below), what they do in this repo, and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
1
+ # OpenSearch JavaScript Client Admins
11
2
 
12
3
  ## Current Admins
13
4
 
14
- | Admin | GitHub ID | Affiliation |
15
- | --------------------- | ------------------------------------------------- | ----------- |
16
- | Anan Zhuang | [ananzh](https://github.com/ananzh) | Amazon |
17
- | Bishoy Boktor | [boktorbb-amzn](https://github.com/boktorbb-amzn) | Amazon |
18
- | Charlotte | [CEHENKLE](https://github.com/CEHENKLE) | Amazon |
19
- | Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon |
20
- | Kawika (Rocky) Avilla | [kavilla](https://github.com/kavilla) | Amazon |
21
- | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
22
- | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
23
- | Tommy Markley | [tmarkley](https://github.com/tmarkley) | Amazon |
24
-
25
- ## Admin Responsibilities
26
-
27
- As an admin you own stewartship of the repository and its settings. Admins have [admin-level permissions on a repository](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization). Use those privileges to serve the community and protect the repository as follows.
28
-
29
- ### Prioritize Security
30
-
31
- Security is your number one priority. Manage security keys and safeguard access to the repository.
32
-
33
- Note that this repository is monitored and supported 24/7 by Amazon Security, see [Reporting a Vulnerability](SECURITY.md) for details.
34
-
35
- ### Enforce Code of Conduct
36
-
37
- Act on [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) violations by revoking access, and blocking malicious actors.
38
-
39
- ### Adopt Organizational Best Practices
40
-
41
- Adopt organizational best practices, work in the open, and collaborate with other admins by opening issues before making process changes. Prefer consistency, and avoid diverging from practices in the opensearch-project organization.
5
+ | Admin | GitHub ID | Affiliation |
6
+ |-----------------------|-----------------------------------------------|-------------|
7
+ | Anan Zhuang | [ananzh](https://github.com/ananzh) | Amazon |
8
+ | Bishoy Boktor | [boktorbb](https://github.com/boktorbb) | Amazon |
9
+ | Charlotte | [CEHENKLE](https://github.com/CEHENKLE) | Amazon |
10
+ | Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon |
11
+ | Kawika (Rocky) Avilla | [kavilla](https://github.com/kavilla) | Amazon |
12
+ | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
13
+ | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
14
+
15
+ [This document](https://github.com/opensearch-project/.github/blob/main/ADMINS.md)
16
+ explains what an admin's responsibilities are.
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # CHANGELOG
2
+ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3
+
4
+ ## [Unreleased]
5
+ ### Added
6
+ - Github workflow for changelog verification ([#306](https://github.com/opensearch-project/opensearch-js/pull/306))
7
+ - Add GitHub and Jenkins release workflow ([#317](https://github.com/opensearch-project/opensearch-js/pull/317))
8
+ ### Dependencies
9
+ - Bumps `tsd` from 0.22.0 to 0.24.1
10
+ - Bumps `semver` from 7.3.7 to 7.3.8
11
+
12
+ ### Changed
13
+
14
+ ### Deprecated
15
+
16
+ ### Removed
17
+
18
+ ### Fixed
19
+ - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
20
+
21
+ ### Security
22
+
23
+
24
+ [Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.0...HEAD
package/COMPATIBILITY.md CHANGED
@@ -17,8 +17,11 @@ The below matrix shows the compatibility of the [`opensearch-js`](https://www.np
17
17
  | 1.2.4 | 1.1.0 |
18
18
  | 1.3.0 | 1.1.0 |
19
19
  | 1.3.1 | 1.1.0 |
20
+ | 1.3.2 | 1.1.0 |
21
+ | 1.3.3 | 1.1.0 |
20
22
  | 2.0.0 | 2.0.0 |
23
+ | 2.0.1 | 2.0.0 |
21
24
 
22
25
  ## Upgrading
23
26
 
24
- Major versions of OpenSearch introduce breaking changes that require careful upgrades of the client. While `opensearch-js` 2.0.0 works against OpenSearch 1.3.1, certain deprecated features removed in OpenSearch 2.0 have also been removed from the client. Please refer to the [OpenSearch documentation](https://opensearch.org/docs/latest/clients/index/) for more information.
27
+ Major versions of OpenSearch introduce breaking changes that require careful upgrades of the client. While `opensearch-js` 2.0.0 works against the latest OpenSearch 1.x, certain deprecated features removed in OpenSearch 2.0 have also been removed from the client. Please refer to the [OpenSearch documentation](https://opensearch.org/docs/latest/clients/index/) for more information.
package/MAINTAINERS.md CHANGED
@@ -1,78 +1,18 @@
1
- - [Overview](#overview)
2
- - [Current Maintainers](#current-maintainers)
3
- - [Maintainer Responsibilities](#maintainer-responsibilities)
4
- - [Uphold Code of Conduct](#uphold-code-of-conduct)
5
- - [Prioritize Security](#prioritize-security)
6
- - [Review Pull Requests](#review-pull-requests)
7
- - [Triage Open Issues](#triage-open-issues)
8
- - [Backports](#backports)
9
- - [Be Responsive](#be-responsive)
10
- - [Maintain Overall Health of the Repo](#maintain-overall-health-of-the-repo)
11
- - [Use Semver](#use-semver)
12
- - [Release Frequently](#release-frequently)
13
- - [Promote Other Maintainers](#promote-other-maintainers)
14
-
15
- ## Overview
16
-
17
- This document explains who the maintainers are (see below), what they do in this repo, and how they should be doing it. If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
1
+ # OpenSearch JavaScript Client Maintainers
18
2
 
19
3
  ## Current Maintainers
20
4
 
21
- | Maintainer | GitHub ID | Affiliation |
22
- | --------------------- | ------------------------------------------------- | ----------- |
23
- | Anan Zhuang | [ananzh](https://github.com/ananzh) | Amazon |
24
- | Bishoy Boktor | [boktorbb-amzn](https://github.com/boktorbb-amzn) | Amazon |
25
- | Kawika (Rocky) Avilla | [kavilla](https://github.com/kavilla) | Amazon |
26
- | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
27
- | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
28
- | Tommy Markley | [tmarkley](https://github.com/tmarkley) | Amazon |
29
-
30
- ## Maintainer Responsibilities
31
-
32
- Maintainers are active and visible members of the community, and have [maintain-level permissions on a repository](https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization). Use those privileges to serve the community and evolve code as follows.
33
-
34
- ### Uphold Code of Conduct
35
-
36
- Model the behavior set forward by the [Code of Conduct](CODE_OF_CONDUCT.md) and raise any violations to other maintainers and admins.
37
-
38
- ### Prioritize Security
39
-
40
- Security is your number one priority. Maintainer's Github keys must be password protected securely and any reported security vulnerabilities are addressed before features or bugs.
41
-
42
- Note that this repository is monitored and supported 24/7 by Amazon Security, see [Reporting a Vulnerability](SECURITY.md) for details.
43
-
44
- ### Review Pull Requests
45
-
46
- Review pull requests regularly, comment, suggest, reject, merge and close. Accept only high quality pull-requests. Provide code reviews and guidance on incomming pull requests. Don't let PRs be stale and do your best to be helpful to contributors.
47
-
48
- ### Triage Open Issues
49
-
50
- Manage labels, review issues regularly, and triage by labelling them.
51
-
52
- All repositories in this organization have a standard set of labels, including `bug`, `documentation`, `duplicate`, `enhancement`, `good first issue`, `help wanted`, `blocker`, `invalid`, `question`, `wontfix`, and `untriaged`, along with release labels, such as `v1.0.0`, `v1.1.0` and `v2.0.0`, and `backport`.
53
-
54
- Use labels to target an issue or a PR for a given release, add `help wanted` to good issues for new community members, and `blocker` for issues that scare you or need immediate attention. Request for more information from a submitter if an issue is not clear. Create new labels as needed by the project.
55
-
56
- ### Backports
57
-
58
- The Github workflow in [backport.yml](.github/workflows/backport.yml) creates backport PRs automatically when the original PR with an appropriate label `backport <backport-branch-name>` is merged to main. To backport a PR to `1.x`, add a label `backport 1.x` to the PR, once this PR is merged to main, the workflow will create a backport PR to the `1.x` branch.
59
-
60
- ### Be Responsive
61
-
62
- Respond to enhancement requests, and forum posts. Allocate time to reviewing and commenting on issues and conversations as they come in.
63
-
64
- ### Maintain Overall Health of the Repo
65
-
66
- Keep the `main` branch at production quality at all times. Backport features as needed. Cut release branches and tags to enable future patches.
67
-
68
- ### Use Semver
69
-
70
- Use and enforce [semantic versioning](https://semver.org/) and do not let breaking changes be made outside of major releases.
71
-
72
- ### Release Frequently
73
-
74
- Make frequent project releases to the community.
75
-
76
- ### Promote Other Maintainers
77
-
78
- Assist, add, and remove [MAINTAINERS](MAINTAINERS.md). Exercise good judgement, and propose high quality contributors to become co-maintainers.
5
+ | Maintainer | GitHub ID | Affiliation |
6
+ |-----------------------|-----------------------------------------------|-------------|
7
+ | Anan Zhuang | [ananzh](https://github.com/ananzh) | Amazon |
8
+ | Bishoy Boktor | [boktorbb](https://github.com/boktorbb) | Amazon |
9
+ | Kawika (Rocky) Avilla | [kavilla](https://github.com/kavilla) | Amazon |
10
+ | Mihir Soni | [mihirsoni](https://github.com/mihirsoni) | Amazon |
11
+ | Sean Neumann | [seanneumann](https://github.com/seanneumann) | Amazon |
12
+ | Daniel Doubrovkine | [dblock](https://github.com/dblock) | Amazon |
13
+ | Vacha Shah | [VachaShah](https://github.com/VachaShah) | Amazon |
14
+ | Theo Truong | [nhtruong](https://github.com/nhtruong) | Amazon |
15
+
16
+ [This document](https://github.com/opensearch-project/.github/blob/main/MAINTAINERS.md)
17
+ explains what maintainers do in this repo, and how they should be doing it.
18
+ If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
package/Makefile CHANGED
@@ -1,19 +1,9 @@
1
- cluster.opendistro.build:
2
- docker-compose --project-directory .ci/opendistro build;
3
-
4
- cluster.opendistro.start:
5
- docker-compose --project-directory .ci/opendistro up -d ;
6
- sleep 20;
7
-
8
- cluster.opendistro.stop:
9
- docker-compose --project-directory .ci/opendistro down ;
10
-
11
1
  cluster.opensearch.build:
12
2
  docker-compose --project-directory .ci/opensearch build;
13
3
 
14
4
  cluster.opensearch.start:
15
5
  docker-compose --project-directory .ci/opensearch up -d ;
16
- sleep 20;
6
+ sleep 60;
17
7
 
18
8
  cluster.opensearch.stop:
19
9
  docker-compose --project-directory .ci/opensearch down ;
@@ -24,4 +14,4 @@ cluster.clean: ## Remove unused Docker volumes and networks
24
14
  docker network prune --force
25
15
  docker system prune --volumes --force
26
16
 
27
- .PHONY: cluster.opendistro.build cluster.opendistro.start cluster.opendistro.stop cluster.opensearch.build cluster.opensearch.start cluster.opensearch.stop cluster.clean
17
+ .PHONY: cluster.opensearch.build cluster.opensearch.start cluster.opensearch.stop cluster.clean
package/README.md CHANGED
@@ -12,7 +12,7 @@ OpenSearch Node.js client
12
12
  - [Welcome!](#welcome)
13
13
  - [Example use](#example-use)
14
14
  - [Setup](#setup)
15
- - [Sample code](#sample-code)
15
+ - [Sample code](#sample-code)
16
16
  - [Project Resources](#project-resources)
17
17
  - [Code of Conduct](#code-of-conduct)
18
18
  - [License](#license)
@@ -44,113 +44,10 @@ Then require the client:
44
44
  const { Client } = require('@opensearch-project/opensearch');
45
45
  ```
46
46
 
47
- ### Sample code
47
+ ## Sample code
48
+
49
+ Please see the [USER_GUIDE](USER_GUIDE.md) for code snippets.
48
50
 
49
- ```javascript
50
- 'use strict';
51
-
52
- var host = 'localhost';
53
- var protocol = 'https';
54
- var port = 9200;
55
- var auth = 'admin:admin'; // For testing only. Don't store credentials in code.
56
- var ca_certs_path = '/full/path/to/root-ca.pem';
57
-
58
- // Optional client certificates if you don't want to use HTTP basic authentication.
59
- // var client_cert_path = '/full/path/to/client.pem'
60
- // var client_key_path = '/full/path/to/client-key.pem'
61
-
62
- // Create a client with SSL/TLS enabled.
63
- var { Client } = require('@opensearch-project/opensearch');
64
- var fs = require('fs');
65
- var client = new Client({
66
- node: protocol + '://' + auth + '@' + host + ':' + port,
67
- ssl: {
68
- ca: fs.readFileSync(ca_certs_path),
69
- // You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch.
70
- // cert: fs.readFileSync(client_cert_path),
71
- // key: fs.readFileSync(client_key_path)
72
- },
73
- });
74
-
75
- async function search() {
76
- // Create an index with non-default settings.
77
- var index_name = 'books';
78
- var settings = {
79
- settings: {
80
- index: {
81
- number_of_shards: 4,
82
- number_of_replicas: 3,
83
- },
84
- },
85
- };
86
-
87
- var response = await client.indices.create({
88
- index: index_name,
89
- body: settings,
90
- });
91
-
92
- console.log('Creating index:');
93
- console.log(response.body);
94
-
95
- // Add a document to the index.
96
- var document = {
97
- title: 'The Outsider',
98
- author: 'Stephen King',
99
- year: '2018',
100
- genre: 'Crime fiction',
101
- };
102
-
103
- var id = '1';
104
-
105
- var response = await client.index({
106
- id: id,
107
- index: index_name,
108
- body: document,
109
- refresh: true,
110
- });
111
-
112
- console.log('Adding document:');
113
- console.log(response.body);
114
-
115
- // Search for the document.
116
- var query = {
117
- query: {
118
- match: {
119
- title: {
120
- query: 'The Outsider',
121
- },
122
- },
123
- },
124
- };
125
-
126
- var response = await client.search({
127
- index: index_name,
128
- body: query,
129
- });
130
-
131
- console.log('Search results:');
132
- console.log(response.body.hits);
133
-
134
- // Delete the document.
135
- var response = await client.delete({
136
- index: index_name,
137
- id: id,
138
- });
139
-
140
- console.log('Deleting document:');
141
- console.log(response.body);
142
-
143
- // Delete the index.
144
- var response = await client.indices.delete({
145
- index: index_name,
146
- });
147
-
148
- console.log('Deleting index:');
149
- console.log(response.body);
150
- }
151
-
152
- search().catch(console.log);
153
- ```
154
51
 
155
52
  ## Project Resources
156
53
 
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
  /*
package/api/api/cat.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
  /*
@@ -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
  /*
@@ -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
  /*
package/api/api/count.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
  /*
package/api/api/create.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
  /*
@@ -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
  /*
package/api/api/delete.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
  /*