class VulnerabilityRepository implements Constants {

	public Map<String, Object> getUniqueHost(String assetGroup, String severity) {

		Map<String, Object> uniqueHost = new HashMap<>();
		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		urlToQuery.append("/").append(SEARCH);
		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"has_child\":{\"type\":\"vulninfo\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"terms\":{\"severitylevel.keyword\":["
						+ severity + "]}}]}}}}]}},\"aggs\":{\"vulninfo\":{\"children\":{\"type\":\"vulninfo\"},"
						+ "\"aggs\":{\"sev-filter\":{\"filter\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"terms\":{\"severitylevel.keyword\":["
						+ severity + "]}}]}},"
						+ "\"aggs\":{\"severity\":{\"terms\":{\"field\":\"severitylevel.keyword\",\"size\":5},"
						+ "\"aggs\":{\"unique-host\":{\"cardinality\":{\"field\":\"_resourceid.keyword\",\"precision_threshold\":40000}}}}}}}}}}");
		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error(Constants.ERROR_UNIQUEHOST, e);
		}

		JsonParser jsonParser = new JsonParser();
		if (StringUtils.isNotEmpty(responseJson)) {
			JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);

			JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get(HITS).toString());
			long total = hitsJson.get(TOTAL).getAsLong();
			uniqueHost.put(TOTAL, total);
			JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
			JsonArray buckets = aggsJson.getAsJsonObject(VULN_INFO).getAsJsonObject("sev-filter")
					.getAsJsonObject(SEVERITY).getAsJsonArray(BUCKETS);
			if (buckets.size() > 0) {
				for (int i = 0; i < buckets.size(); i++) {
					uniqueHost.put(buckets.get(i).getAsJsonObject().get("key").getAsString(), buckets.get(i)
							.getAsJsonObject().get("unique-host").getAsJsonObject().get(VALUE).getAsLong());
				}
			}
		}
		return uniqueHost;
	}

}