class ElasticSearchRepository implements Constants {

	public Map<String, Long> getTotalDistributionForIndexAndType(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, int size, Map<String, Object> mustTermsFilter)
			throws Exception {

		String urlToQuery = buildAggsURL(esUrl, index, type);
		Map<String, Object> requestBody = new HashMap<String, Object>();
		Map<String, Object> matchFilters = Maps.newHashMap();
		Map<String, Long> distribution = new HashMap<String, Long>();
		if (mustFilter == null) {
			matchFilters.put("match_all", new HashMap<String, String>());
		} else {
			matchFilters.putAll(mustFilter);
		}
		if (null != mustFilter) {
			requestBody.put(QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, null, mustTermsFilter,null));
			requestBody.put(AGGS, buildAggs(aggsFilter, size));

			if (!Strings.isNullOrEmpty(aggsFilter)) {
				requestBody.put(SIZE, "0");
			}

		} else {
			requestBody.put(QUERY, matchFilters);
		}
		String responseDetails = null;
		Gson gson = new GsonBuilder().create();

		try {
			String requestJson = gson.toJson(requestBody, Object.class);
			responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson);
			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(NAME);
			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);
				distribution.put(bucket.get("key").toString(), ((Double) bucket.get("doc_count")).longValue());
			}

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

}