class ElasticSearchRepository implements Constants {

	@SuppressWarnings("unchecked")
	public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String searchText,
			Map<String, Object> mustTermsFilter,
			Map<String, List<String>> matchPhrasePrefix) throws Exception {

		String urlToQuery = buildCountURL(esUrl, index, type);

		Map<String, Object> requestBody = new HashMap<String, Object>();
		Map<String, Object> matchFilters = Maps.newHashMap();
		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,
							searchText, mustTermsFilter, matchPhrasePrefix));
		} 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, Object.class);
			return (long) (Double.parseDouble(response.get(COUNT).toString()));
		} catch (Exception e) {
			LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e);
			throw e;
		}
	}

}