/*
 * Copyright 2015 Sergej Meister
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intellijob;

import org.apache.log4j.Logger;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
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.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.util.StringUtils;

import javax.annotation.PreDestroy;

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.intellijob.elasticsearch.repository")
public class ElasticsearchConfiguration {

    private static final Logger LOG = Logger.getLogger(ElasticsearchConfiguration.class);

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

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

    @Value("${elasticsearch.http.enabled}")
    private boolean httpEnabled;

    @Value("${elasticsearch.http.cors.enabled}")
    private boolean httpCorsEnabled;

    @Value("${elasticsearch.path.data}")
    private String pathData;

    private Node node;

    /**
     * Init elasticsearch client and returns ElasticsearchTemplate for Cluster civs.
     *
     * @return default ElasticsearchTemplate for Cluster intelliJob.
     */
    @Bean
    public ElasticsearchTemplate elasticsearchTemplate() {
        LOG.info("Start elasticsearch server");
        NodeBuilder nodeBuilder = new NodeBuilder();
        nodeBuilder.clusterName(clusterName).local(false);
        if (StringUtils.hasLength(pathData)) {
            nodeBuilder.settings().put("path.data", pathData);
        }
        nodeBuilder.settings().put("http.enabled", httpEnabled);
        nodeBuilder.settings().put("http.cors.enabled", httpCorsEnabled);
        nodeBuilder.settings().put("network.host", host);

        node = nodeBuilder.node();
        return new ElasticsearchTemplate(node.client());
    }

    @PreDestroy
    void destroy() {
        if (node != null) {
            LOG.info("Destroy elasticsearch server.");
            try {
                node.close();
            } catch (Exception e) {
                LOG.error("Elasticsearch server can not be destroyed!", e);
            }
        }
    }

    public Node getNode() {
        return node;
    }

}

@@ -1842,54 +1842,34 @@
 and 
-returns ElasticsearchTemplate for C
+open connection to c
 luster
- civs
 .%0A  
@@ -1922,30 +1922,28 @@
 ate 
-for Cluster intelliJob
+connected to cluster
 .%0A  
@@ -2590,24 +2590,77 @@
 ());%0A    %7D%0A%0A
+%0A    /**%0A     * Close connection to cluster!%0A     */%0A
     @PreDest

improve code commentar in elastic configuration