You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';varhost='localhost';varprotocol='https';varport=9200;varauth='admin:admin';// For testing only. Don't store credentials in code.varca_certs_path='/full/path/to/root-ca.pem';// Optional client certificates if you don't want to use HTTP basic authentication.// var client_cert_path = '/full/path/to/client.pem'// var client_key_path = '/full/path/to/client-key.pem'// Create a client with SSL/TLS enabled.var{ Client }=require('@opensearch-project/opensearch');varfs=require('fs');varclient=newClient({node: protocol+'://'+auth+'@'+host+':'+port,ssl: {ca: fs.readFileSync(ca_certs_path),// You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch.// cert: fs.readFileSync(client_cert_path),// key: fs.readFileSync(client_key_path)},});
Authenticate with Amazon OpenSearch Service
Using AWS V2 SDK
constAWS=require('aws-sdk');// V2 SDK.const{ Client }=require('@opensearch-project/opensearch');const{ AwsSigv4Signer }=require('@opensearch-project/opensearch/aws');constclient=newClient({
...AwsSigv4Signer({region: 'us-west-2',service: 'es',// 'aoss' for OpenSearch Serverless// Must return a Promise that resolve to an AWS.Credentials object.// This function is used to acquire the credentials when the client start and// when the credentials are expired.// The Client will refresh the Credentials only when they are expired.// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials.// Example with AWS SDK V2:getCredentials: ()=>newPromise((resolve,reject)=>{// Any other method to acquire a new Credentials object can be used.AWS.config.getCredentials((err,credentials)=>{if(err){reject(err);}else{resolve(credentials);}});}),}),node: 'https://search-xxx.region.es.amazonaws.com',// OpenSearch domain URL// node: "https://xxx.region.aoss.amazonaws.com" for OpenSearch Serverless});
Using AWS V3 SDK
const{ defaultProvider }=require('@aws-sdk/credential-provider-node');// V3 SDK.const{ Client }=require('@opensearch-project/opensearch');const{ AwsSigv4Signer }=require('@opensearch-project/opensearch/aws');constclient=newClient({
...AwsSigv4Signer({region: 'us-east-1',service: 'es',// 'aoss' for OpenSearch Serverless// Must return a Promise that resolve to an AWS.Credentials object.// This function is used to acquire the credentials when the client start and// when the credentials are expired.// The Client will refresh the Credentials only when they are expired.// With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials.// Example with AWS SDK V3:getCredentials: ()=>{// Any other method to acquire a new Credentials object can be used.constcredentialsProvider=defaultProvider();returncredentialsProvider();},}),node: 'https://search-xxx.region.es.amazonaws.com',// OpenSearch domain URL// node: "https://xxx.region.aoss.amazonaws.com" for OpenSearch Serverless});
console.log('Creating a PIT:');varresponse=awaitclient.createPit({index: 'books*',keep_alive: '100m',expand_wildcards: 'all',});console.log(response.body);
Get all PITs
console.log('Getting all PITs:');varresponse=awaitclient.getAllPits();console.log(response.body);
Delete a Point in Time
console.log('Deleting a PIT:');varresponse=awaitclient.deletePit({body: {pit_id: ['o463QQEPbXktaW5kZXgtMDAwMDAxFkhGN09fMVlPUkVPLXh6MUExZ1hpaEEAFjBGbmVEZHdGU1EtaFhhUFc4ZkR5cWcAAAAAAAAAAAEWaXBPNVJtZEhTZDZXTWFFR05waXdWZwEWSEY3T18xWU9SRU8teHoxQTFnWGloQQAA',],},});console.log(response.body);
Delete all PITs
console.log('Deleting all PITs:');varresponse=awaitclient.deleteAllPits();console.log(response.body);