Skip to content

Commit

Permalink
Use AWS_REGION.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Dec 26, 2022
1 parent a0864a7 commit ad6b81b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Create an OpenSearch domain in (AWS) which support IAM based AuthN/AuthZ and run
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_REGION=us-west-2
export OPENSEARCH_ENDPOINT=https://....us-west-2.es.amazonaws.com
export OPENSEARCH_REGION=us-west-2
ts-node src/index.ts
```
Expand All @@ -50,12 +50,7 @@ The [code](src/index.ts) will connect to OpenSearch, display its version, create
```
opensearch: 2.3.0
{
_index: 'sample-index',
_id: '1',
_score: 0.2876821,
_source: { first_name: 'Bruce' }
}
{ title: 'Moneyball', director: 'Bennett Miller', year: 2011 }
```

## License
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws');
async function main() {
const client = new Client({
...AwsSigv4Signer({
region: process.env.OPENSEARCH_REGION || 'us-east-1',
region: process.env.AWS_REGION || 'us-east-1',
getCredentials: () => {
const credentialsProvider = defaultProvider();
return credentialsProvider();
Expand All @@ -29,20 +29,20 @@ async function main() {
console.log(version.distribution + ": " + version.number);

// create an index
const index = 'sample-index'
const index = 'movies'
await client.indices.create({ index: index })

try {
// index data
const document = { first_name: 'Bruce' };
const document = { title: 'Moneyball', director: 'Bennett Miller', year: 2011 };
await client.index({ index: index, body: document, id: '1', refresh: true })

// wait for the document to index
await new Promise(r => setTimeout(r, 3000));
await new Promise(r => setTimeout(r, 1000));

// search for the document
var results = await client.search({ body: { query: { match: { first_name: 'bruce' } } } });
results.body.hits.hits.forEach((hit) => console.log(hit));
var results = await client.search({ body: { query: { match: { director: 'miller' } } } });
results.body.hits.hits.forEach((hit) => console.log(hit._source));

// delete the document
await client.delete({ index: index, id: '1' })
Expand Down

0 comments on commit ad6b81b

Please sign in to comment.