'use strict';

const { Client } = require('@elastic/elasticsearch');

exports.esConnection = (esConfig) => {
    let url;

    if (esConfig.url !== undefined && esConfig.url !== ""){
        url = esConfig.url;
    } else {
        url = 'http://';

        if (esConfig.username && esConfig.password) {
            url += esConfig.username + ':' + esConfig.password + '@';
        }

        url += esConfig.host;
    }
    
    return new Client({ node: url });
};
