class VulnerabilityRepository implements Constants {

	public Map<String, Long> getAppsBySeverity(String assetGroup, String parentType, String severity) throws Exception {

		Map<String, Long> appDetails = new HashMap<>();
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		urlToQuery.append("/").append(parentType);
		urlToQuery.append("/").append(SEARCH);

		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":true}}]}},"
						+ "\"aggs\":{\"apps\":{\"terms\":{\"field\":\"tags.Application.keyword\",\"size\":10000},"
						+ "\"aggs\":{\"vulns\":{\"children\":{\"type\":\"vulninfo\"},\"aggs\":{\"NAME\":{\"filters\":{\"filters\":{\"severity\":{\"terms\":{\"severitylevel.keyword\":[");
		requestBody.append(severity);
		requestBody.append("]}}}}}}}}}}}");
		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error("Error in getAppsBySeverity from ES", e);
			throw e;
		}
		JsonParser jsonParser = new JsonParser();
		JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
		JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
		JsonArray buckets = aggsJson.getAsJsonObject("apps").getAsJsonArray(BUCKETS);
		if (buckets.size() > 0) {
			for (int i = 0; i < buckets.size(); i++) {
				appDetails.put(buckets.get(i).getAsJsonObject().get("key").getAsString(),
						buckets.get(i).getAsJsonObject().getAsJsonObject("vulns").getAsJsonObject("NAME")
								.getAsJsonObject("buckets").getAsJsonObject("severity").get(DOC_COUNT).getAsLong());
			}
		}
		return appDetails;
	}

}