Skip to content

Commit

Permalink
Update README. Add section for post-deployment search API calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitagarwala01 committed Dec 7, 2023
1 parent d0c9c22 commit 1493ea1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ const client = await search()

Now `client` is an instance of the [OpenSearch JavaScript client](https://opensearch.org/docs/latest/clients/javascript/index/), and you can call any client method on it — for example, [`client.index.create()`](https://opensearch.org/docs/latest/clients/javascript/index/#creating-an-index), [`client.index()`](https://opensearch.org/docs/latest/clients/javascript/index/#indexing-a-document), or [`client.search()`](https://opensearch.org/docs/latest/clients/javascript/index/#searching-for-documents).

## Making post-deployment requests to OpenSearch or ElasticSearch from your application

If you would like to make requests to automatically configure your OpenSearch or ElasticSearch instance after deployment, you may optionally add a postdeploy-search.js file in the root directory of your Architect project. This file should export a function that takes no arguments as its default export. Be sure to connect with your OpenSearch or ElasticSearch instance before making your requests.

Here's an sample postdeploy-search.js file for making requests to OpenSearch:

```ts
import { search } from '@nasa-gcn/architect-functions-search'

export default async function () {
const client = await search()

//Set cluster settings
const cluster_settings_request = {
method: 'PUT',
path: '/_cluster/settings',
body: {
persistent: {
cluster.max_shards_per_node: '500',
},
},
}

try {
await client.transport.request(cluster_settings_request)
} catch (e) {
console.log('Error: ', e)
return
}
}
```

## Advanced usage from your application

If you would like to manually connect to OpenSearch from your application, then you will need to sign your requests using [AWS SIG4](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html); the OpenSearch client library provides the [`AwsSigv4Signer`](https://opensearch.org/docs/latest/clients/javascript/index/#authenticating-with-amazon-opensearch-service--aws-sigv4) helper to automate this.
Expand Down

0 comments on commit 1493ea1

Please sign in to comment.