package org.superdev.coddy.application.elasticsearch;


import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

import java.net.InetAddress;

@Configuration
@EnableElasticsearchRepositories(basePackages = "org.superdev.coddy.*.elasticsearch.repository")
public class EsConfig {

    @Value("${elasticsearch.host}")
    private String esHost;

    @Value("${elasticsearch.port}")
    private int esPort;

    @Value("${elasticsearch.clustername}")
    private String esClusterName;

    @Bean
    public Client client() throws Exception {

        Settings esSettings = Settings.settingsBuilder()
                .put("cluster.name", esClusterName)
                .build();

        //https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html
        return TransportClient.builder()
                .settings(esSettings)
                .build()
                .addTransportAddress(
                        new InetSocketTransportAddress(InetAddress.getByName(esHost), esPort));
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }
}
@@ -152,59 +152,8 @@
 nt;%0A
-import org.elasticsearch.common.settings.Settings;%0A
 impo
@@ -939,272 +939,58 @@
    @
-Value(%22$%7Belasticsearch.clustername%7D%22)%0A    private String esClusterName;%0A%0A    @Bean%0A    public Client client() throws Exception %7B%0A%0A        Settings esSettings = Settings.settingsBuilder()%0A                .put(%22cluster.name%22, esClusterName)%0A                .build();
+Bean%0A    public Client client() throws Exception %7B
 %0A%0A  
@@ -1144,46 +1144,8 @@
 r()%0A
-                .settings(esSettings)%0A
     

remove cluster name in EsConfig