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 0efc3c3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,54 @@ 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: {
plugins: {
ml_commons: {
only_run_on_ml_node: 'false',
model_access_control_enabled: 'true',
native_memory_threshold: '99',
},
},
},
},
}

try {
const resp = await client.transport.request(cluster_settings_request)

if (resp && resp.statusCode == 200) {
console.log('Updated ML-related cluster settings.')
} else {
console.log(
'Error. Could not update cluster settings. Returned with response: ',
resp
)
return
}
} 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 0efc3c3

Please sign in to comment.