package eu.eudat.configurations;

import org.apache.http.HttpHost;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

/**
 * Created by ikalyvas on 7/5/2018.
 */
@Configuration
public class ElasticSearchConfiguration {

    private Environment environment;

    @Autowired
    public ElasticSearchConfiguration(Environment environment) {
        this.environment = environment;
    }

    @Bean
    public RestHighLevelClient client() throws Exception {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(this.environment.getProperty("elasticsearch.host"),
                                Integer.parseInt(this.environment.getProperty("elasticsearch.port")), "http")));
        return client;
    }
}
