class TaggingRepositoryImpl implements TaggingRepository, Constants {

    @Override
    public String getTaggingByApplication(String ag, String targetType)
            throws DataException {
        StringBuilder requestBody = new StringBuilder();
        StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(
                ag);
        if (!StringUtils.isEmpty(targetType)) {
            urlToQuery.append("/").append(targetType);
            urlToQuery.append("/").append(UNDERSCORE_COUNT);
            requestBody
                    .append("{\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}}],\"must_not\":[{\"exists\":{\"field\":\"tags.Application\"}}]}}}");
        } else {
            urlToQuery.append("/").append(SEARCH);
            requestBody
                    .append("{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}}],\"must_not\":[{\"exists\":{\"field\":\"tags.Application\"}}]}},\"aggs\":{\"NAME\":{\"terms\":{\"field\":\"_entitytype.keyword\",\"size\":"
                            + TEN_THOUSAND + "}}}}");
        }

        String responseJson = "";
        try {
            responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(),
                    requestBody.toString());
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new DataException(e);
        }
        return responseJson;
    }

}