class VulnerabilityRepository implements Constants {

	public Map<String, Object> getAllQidByAG(String assetGroup, String severity) throws DataException {

		Map<String, Object> qids = new HashMap<>();

		StringBuilder urlToQuery = new StringBuilder(esUrl).append("/").append(assetGroup);
		urlToQuery.append("/").append(VULN_INFO);
		urlToQuery.append("/").append(SEARCH);
		StringBuilder requestBody = new StringBuilder(
				"{\"size\":0,\"query\":{\"bool\":{\"must\":[{\"match\":{\"latest\":\"true\"}},{\"terms\":{\"severitylevel.keyword\":[");
		requestBody.append(severity);
		requestBody.append(
				"]}}]}},\"aggs\":{\"qid\":{\"terms\":{\"script\":\"(doc['qid.keyword'].value+'~').replace('.0','')+doc['title.keyword'].value.toLowerCase()+'~'+doc['classification.keyword'].value\",\"size\":100000}}}}");

		String responseJson = "";
		try {
			responseJson = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
		} catch (Exception e) {
			LOGGER.error("Error in getAllQidByAG from ES", e);
			throw new DataException(e);
		}
		JsonParser jsonParser = new JsonParser();
		JsonObject resultJson = (JsonObject) jsonParser.parse(responseJson);
		JsonObject aggsJson = (JsonObject) jsonParser.parse(resultJson.get(AGGREGATIONS).toString());
		JsonArray buckets = aggsJson.getAsJsonObject("qid").getAsJsonArray(BUCKETS);
		if (buckets.size() > 0) {
			for (int i = 0; i < buckets.size(); i++) {
				qids.put(buckets.get(i).getAsJsonObject().get("key").toString().replace("\"", ""),
						buckets.get(i).getAsJsonObject().get(DOC_COUNT));
			}
		}
		return qids;
	}

}