package kr.gmtc.gw.elastic.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

@Configuration
//@EnableElasticsearchRepositories(basePackages = "kr.gmtc.gw.elk.repositories")
@ComponentScan(basePackages = {"kr.gmtc.gw.elk"})
public class ElasticsearchClientConfig extends AbstractElasticsearchConfiguration {

    @Value("${app.config.elastic.host}")
    private String gsEsHost;

    @Value("${app.config.elastic.port}")
    private String gsEsPort;

    @Override
    @Bean(destroyMethod = "close")
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration =
                ClientConfiguration
                        .builder()
                         .connectedTo(gsEsHost + ":" + gsEsPort)
                        //.connectedTo( "10.200.31.129:9200")
                        .build();

        return RestClients.create(clientConfiguration).rest();
    }
    
}
