class ElasticSearchDataPublisher {

    public int publishAutoFixTransactions(List<AutoFixTransaction> autoFixTrans, Map<String, String> ruleParam) {

        if (autoFixTrans != null && autoFixTrans.size() == 0) {
            return 0;
        }

        BulkRequest bulkRequest = new BulkRequest();
        Gson gson = new Gson();
        StringBuffer bulkRequestBody = new StringBuffer();
        String response = "";
        List<Map<String, Map>> responseList = new ArrayList<>();
        String esUrl = ESUtils.getEsUrl();
        String bulkPostUrl = esUrl + AnnotationPublisher.BULK_WITH_REFRESH_TRUE;
        final String autoFixType= PacmanSdkConstants.TYPE_FOR_AUTO_FIX_RECORD+"_"+ruleParam.get(PacmanSdkConstants.TARGET_TYPE);
        for (AutoFixTransaction autoFixTransaction : autoFixTrans) {
            
            // first post auto fix as child doc of type
            if(AutoFixAction.AUTOFIX_ACTION_FIX.equals(autoFixTransaction.getAction()))
            {   
                if(!ESUtils.isValidType(ESUtils.getEsUrl(),getIndexName(ruleParam),autoFixType)){
                try {
                        ESUtils.createMappingWithParent(ESUtils.getEsUrl(),getIndexName(ruleParam),autoFixType, ruleParam.get(PacmanSdkConstants.TARGET_TYPE));
                } catch (Exception e) {
                    logger.error("uanble to create child type");
                }
            }
                try{
                    // parent child document seems to have some issue
                    bulkRequestBody.append(String.format(BULK_INDEX_REQUEST_TEMPLATE, getIndexName(ruleParam),getDocId(autoFixTransaction), autoFixType));
                    bulkRequestBody.append(gson.toJson(autoFixTransaction));
                    bulkRequestBody.append("\n");
                    if (bulkRequestBody.toString().getBytes().length
                            / (1024 * 1024) >= PacmanSdkConstants.ES_MAX_BULK_POST_SIZE) {
                        response = CommonUtils.doHttpPost(bulkPostUrl, bulkRequestBody.toString(),new HashMap());
                        responseList.add(gson.fromJson(response, Map.class));
                        bulkRequestBody.setLength(0);
                    }
                }catch (Exception e) {
                    logger.error("error occured while indexing auto fix document",e);
                    autoFixTransaction.setAdditionalInfo("error occured while indexing auto fix document " + e.getMessage());
                }
            }
            // build transaction log
            IndexRequest indexRequest = new IndexRequest(
                    CommonUtils.getPropValue(PacmanSdkConstants.AUTO_FIX_TRAN_INDEX_NAME_KEY),
                    CommonUtils.getPropValue(PacmanSdkConstants.AUTO_FIX_TRAN_TYPE_NAME_KEY));
            indexRequest.source(gson.toJson(autoFixTransaction), XContentType.JSON);
            bulkRequest.add(indexRequest);
        }
        
        // post the remaining data if available
            if (bulkRequestBody.length() > 0) {
                response = CommonUtils.doHttpPost(bulkPostUrl, bulkRequestBody.toString(),new HashMap<>());
            }
            responseList.add(gson.fromJson(response, Map.class));
        
        // now post transaction log
        try {
            if(null!=client){
                   BulkResponse bulkResponse = client.bulk(bulkRequest);
                   if (bulkResponse.hasFailures()) {
                       if (!isIndexAvaialble(bulkResponse.getItems())) {
                           logger.info("index not found to write the transaction logs, creating one");
                            // version 5.6 does not support index creation via API,
                            // hence executing a post
                            try {
                                CommonUtils
                                    .doHttpPut(
                                        ESUtils.getEsUrl() + "/"
                                                + CommonUtils
                                                        .getPropValue(PacmanSdkConstants.AUTO_FIX_TRAN_INDEX_NAME_KEY),
                                        "");
                                publishAutoFixTransactions(autoFixTrans,ruleParam); // index should be created now
                            } catch (Exception e) {

                        logger.error("error creating index", e);
                        }
                       }
                   }
            }
        } catch (IOException e) {
            logger.error("error posting auto fix transaction log", e);
            return -1;
        }
        return 0;
    }

    public  ElasticSearchDataPublisher();
    public  ElasticSearchDataPublisher(Boolean testMode);

}