function postDataToES()

in Code.gs [357:381]


function postDataToES(host,data) {
  var url = [(host.use_ssl) ? 'https://' : 'http://',
             host.host,':',host.port,'/_bulk'].join('');
  var options = getDefaultOptions(host.username,host.password);
  options.method = 'POST';
  options['payload'] = data;
  options.headers["Content-Type"] = "application/json";
  options['muteHttpExceptions'] = true;
  var resp = null;
  try {
    resp = UrlFetchApp.fetch(url, options);
  } catch(e) {
    throw "There was an error sending data to the cluster. Please check your connection details and data."
  }
  if(resp.getResponseCode() != 200) {
    var jsonData = JSON.parse(resp.getContentText());
    if(jsonData.error) {
      if(jsonData.error.indexOf('AuthenticationException')>=0) {
        throw "The username and/or password is incorrect."
      }
      throw jsonData.error;
    }
    throw "Your cluster returned an unknown error. Please check your connection details and data."
  }
}