class ElasticSearchRepository implements Constants {

	public Map<String, String> getAccountsByMultiAggs(String index, String type, Map<String, Object> filter,
			Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter,
			Map<String, Object> aggsFilter, int size) throws Exception {

		StringBuilder requestBody = null;
		StringBuilder urlToQuery = null;
		Map<String, Object> matchFilters = Maps.newHashMap();
		Map<String, String> distribution = new HashMap<String, String>();
		if (filter == null) {
			matchFilters.put("match_all", new HashMap<String, String>());
		} else {
			matchFilters.putAll(filter);
		}
		if (null != filter) {
			urlToQuery = new StringBuilder(esUrl).append(FORWARD_SLASH).append(index);
			urlToQuery.append(FORWARD_SLASH).append(_SEARCH);

			requestBody = new StringBuilder("{\"aggs\":{\"accountid\":{\"terms\":{\"field\":\"");
			requestBody.append("accountid.keyword");
			requestBody.append("\",\"size\":" + size + "},"
					+ "\"aggs\":{\"accountname\":{\"terms\":{\"field\":\"accountname.keyword\",\"size\":" + size
					+ "}}}}}}");

		}

		String responseDetails = null;
		Gson gson = new GsonBuilder().create();

		try {
			responseDetails = PacHttpUtils.doHttpPost(urlToQuery.toString(), requestBody.toString());
			Map<String, Object> response = (Map<String, Object>) gson.fromJson(responseDetails, Map.class);
			Map<String, Object> aggregations = (Map<String, Object>) response.get("aggregations");
			Map<String, Object> name = (Map<String, Object>) aggregations.get("accountid");
			List<Map<String, Object>> buckets = (List<Map<String, Object>>) name.get("buckets");

			for (int i = 0; i < buckets.size(); i++) {
				Map<String, Object> bucket = buckets.get(i);
				Map<String, Object> accName = (Map<String, Object>) bucket.get("accountname");
				List<Map<String, Object>> bucketsName = (List<Map<String, Object>>) accName.get("buckets");
				for (int j = 0; j < bucketsName.size(); j++) {
					Map<String, Object> bucketAccName = bucketsName.get(j);
					distribution.put(bucket.get("key").toString(), bucketAccName.get("key").toString());
				}
			}

		} catch (Exception e) {
			LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e);
			throw e;
		}
		return distribution;
	}

}