// Path: elasticservice/src/main/java/elasticsearch/ElasticRestClient.java
// @Component
// public class ElasticRestClient extends AbstractFactoryBean<RestClient> {
//     private static Logger logger = Logger.getLogger(ElasticRestClient.class);
//     private ClusterFailureListener clusterFailureListener;
//     private volatile RestClient restClient;
//     private static List<String> hosts = new ArrayList<>();
//     private Sniffer sniffer;
// 
//     static {
//         hosts.add("10.128.161.107:9200");
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return RestClient.class;
//     }
// 
// 
//     @Override
//     public RestClient createInstance() throws Exception {
//         if (this.restClient != null) {
//             return this.restClient;
//         }
// 
//         HttpHost[] addresses = new HttpHost[hosts.size()];
//         for (int i = 0; i < hosts.size(); i++) {
//             addresses[i] = HttpHost.create(hosts.get(i));
//         }
// 
//         this.restClient = RestClient
//                 .builder(addresses)
//                 .setMaxRetryTimeoutMillis(ESConstants.RESTCLIENT_TIMEOUT)
//                 .build();
// 
// //        this.sniffer = Sniffer.builder(this.restClient)
// //                                 .setSniffIntervalMillis(60000).build();
// 
//         return this.restClient;
//     }
// 
//     @Override
//     protected void destroyInstance(RestClient instance) throws Exception {
//         try {
//             logger.info("Closing sniffer");
//             instance.close();
//             this.sniffer.close();
//         } catch (IOException e) {
//             logger.warn("Error during close sniffer", e);
//         }
//     }
// 
//     public void setHosts(List<String> hosts) {
//         this.hosts = hosts;
//     }
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/constant/ESConstants.java
// public class ESConstants {
//     public      static  final   String STORE_INDEX = "stores";
//     public      static  final   String PRODUCT_TYPE = "product";
//     public      static  final   String SKU_TYPE = "sku";
//     public      static  final   String PRODUCT_PROPERTY = "productproperty";
//     public      static  final   String CHANNEL_TYPE = "channels";
//     public      static  final   int SNIFFER_INTERVAL = 15000;
//     public      static  final   int RESTCLIENT_TIMEOUT = 20000; // 20s
// 
// 
//     public      static  final   Pattern ROUTINGKEY_PATTERN = Pattern.compile("([\\w\\.]+)\\.(\\w+)\\.(\\d+)");
// 
// }


import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import elasticsearch.ElasticRestClient;
import elasticsearch.constant.ESConstants;
import elasticsearch.esapi.resp.*;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Executor;

package elasticsearch.exportimport;



/**
 * Created by I311352 on 11/26/2016.
 */

@Service
public class LoadData {
    private static final Logger logger = LoggerFactory.getLogger(LoadData.class);
    private RestClient client = null;//new ElasticRestClient().createInstance();
    private final Gson gson = new Gson();

    //bulk operation
    private final Integer STEP_SIZE = 500;
    // aggregate fields

    public void saveData(String fileName, Long tenantId, String s3buket, String EShosts) throws Exception {

// Path: elasticservice/src/main/java/elasticsearch/ElasticRestClient.java
// @Component
// public class ElasticRestClient extends AbstractFactoryBean<RestClient> {
//     private static Logger logger = Logger.getLogger(ElasticRestClient.class);
//     private ClusterFailureListener clusterFailureListener;
//     private volatile RestClient restClient;
//     private static List<String> hosts = new ArrayList<>();
//     private Sniffer sniffer;
// 
//     static {
//         hosts.add("10.128.161.107:9200");
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return RestClient.class;
//     }
// 
// 
//     @Override
//     public RestClient createInstance() throws Exception {
//         if (this.restClient != null) {
//             return this.restClient;
//         }
// 
//         HttpHost[] addresses = new HttpHost[hosts.size()];
//         for (int i = 0; i < hosts.size(); i++) {
//             addresses[i] = HttpHost.create(hosts.get(i));
//         }
// 
//         this.restClient = RestClient
//                 .builder(addresses)
//                 .setMaxRetryTimeoutMillis(ESConstants.RESTCLIENT_TIMEOUT)
//                 .build();
// 
// //        this.sniffer = Sniffer.builder(this.restClient)
// //                                 .setSniffIntervalMillis(60000).build();
// 
//         return this.restClient;
//     }
// 
//     @Override
//     protected void destroyInstance(RestClient instance) throws Exception {
//         try {
//             logger.info("Closing sniffer");
//             instance.close();
//             this.sniffer.close();
//         } catch (IOException e) {
//             logger.warn("Error during close sniffer", e);
//         }
//     }
// 
//     public void setHosts(List<String> hosts) {
//         this.hosts = hosts;
//     }
// }
// 
// Path: elasticservice/src/main/java/elasticsearch/constant/ESConstants.java
// public class ESConstants {
//     public      static  final   String STORE_INDEX = "stores";
//     public      static  final   String PRODUCT_TYPE = "product";
//     public      static  final   String SKU_TYPE = "sku";
//     public      static  final   String PRODUCT_PROPERTY = "productproperty";
//     public      static  final   String CHANNEL_TYPE = "channels";
//     public      static  final   int SNIFFER_INTERVAL = 15000;
//     public      static  final   int RESTCLIENT_TIMEOUT = 20000; // 20s
// 
// 
//     public      static  final   Pattern ROUTINGKEY_PATTERN = Pattern.compile("([\\w\\.]+)\\.(\\w+)\\.(\\d+)");
// 
// }


// Path: elasticservice/src/main/java/elasticsearch/exportimport/LoadData.java
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import elasticsearch.ElasticRestClient;
import elasticsearch.constant.ESConstants;
import elasticsearch.esapi.resp.*;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.entity.StringEntity;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Executor;

package elasticsearch.exportimport;



/**
 * Created by I311352 on 11/26/2016.
 */

@Service
public class LoadData {
    private static final Logger logger = LoggerFactory.getLogger(LoadData.class);
    private RestClient client = null;//new ElasticRestClient().createInstance();
    private final Gson gson = new Gson();

    //bulk operation
    private final Integer STEP_SIZE = 500;
    // aggregate fields

    public void saveData(String fileName, Long tenantId, String s3buket, String EShosts) throws Exception {

        ElasticRestClient sclient = new ElasticRestClient();
