Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marthydavid/31192d95590f2e165387b8416206e522 to your computer and use it in GitHub Desktop.
Save marthydavid/31192d95590f2e165387b8416206e522 to your computer and use it in GitHub Desktop.
JavaScript
import elasticsearch from 'elasticsearch';
import config from './config';
export function getClient() {
if (config.get('use_ssl') == true){
if (config.get('es_username')){
var client = new elasticsearch.Client({
hosts: `https://${config.get('es_username')}:${config.get('es_password')}@${config.get('es_host')}:${config.get('es_port')}`,
ssl: {
ca: fs.readFileSync(`${config.get('ca_certs')}`),
rejectUnauthorized: true
}
});
}
else{
var client = new elasticsearch.Client({
hosts: `https://${config.get('es_host')}:${config.get('es_port')}`,
ssl: {
ca: fs.readFileSync(`${config.get('ca_certs')}`),
rejectUnauthorized: true
}
});
}
var client = new elasticsearch.Client({
hosts: `https://${config.get('es_host')}:${config.get('es_port')}`,
ssl: {
ca: fs.readFileSync(`${config.get('ca_certs')}`),
rejectUnauthorized: true
}
});
}
var client = new elasticsearch.Client({
hosts: [ `http://${config.get('es_host')}:${config.get('es_port')}`]
});
return client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment