code: async function connect() {
    
    let esConfig
    let client
  
    // use local client
    if (!process.env.ES_HOST) {
      client = new elasticsearch.Client({host: 'localhost:9200'})
    } else {
      await new Promise((resolve, reject) => AWS.config.getCredentials((err) => {
        if (err) return reject(err)
        resolve()
      }))
  
      esConfig = {
        host: process.env.ES_HOST,
        connectionClass: httpAwsEs,
        amazonES: {
          region: process.env.AWS_DEFAULT_REGION || 'us-east-1',
          credentials: AWS.config.credentials
        },
        // Note that this doesn't abort the query.
        requestTimeout: 120000  // milliseconds
      }
      client = new elasticsearch.Client(esConfig)
    }
  
    await new Promise((resolve, reject) => client.ping({requestTimeout: 1000}, (err) => {
      if (err) {
        console.log('unable to connect to elasticsearch')
        reject('unable to connect to elasticsearch')
      } else {
        resolve()
      }
    }))
    return client
  }
docs: Connect to an Elasticsearch cluster