Created
July 3, 2019 11:22
-
-
Save marthydavid/31192d95590f2e165387b8416206e522 to your computer and use it in GitHub Desktop.
JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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