class ElasticSearchRepository implements Constants {

	public List<LinkedHashMap<String, Object>> getDetailsFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter) throws Exception {

		StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append(FORWARD_SLASH).append(dataSource);
		if (!Strings.isNullOrEmpty(targetType)) {
			urlToQueryBuffer.append(FORWARD_SLASH).append(targetType);
		}
		urlToQueryBuffer.append(FORWARD_SLASH).append(_SEARCH);
		if (size > 0 && from >= 0) {
			urlToQueryBuffer.append("?").append("size=").append(size).append("&").append("from=").append(from);
		}
		String urlToQuery = urlToQueryBuffer.toString();
		List<LinkedHashMap<String, Object>> results = new ArrayList<LinkedHashMap<String, Object>>();

		Map<String, Object> requestBody = new HashMap<String, Object>();
		Map<String, Map<String, String>> auditDate = new HashMap<String, Map<String, String>>();
		Map<String, String> order = new HashMap<String, String>();
		order.put(ORDER, "desc");
		auditDate.put("auditdate", order);
		List<Map<String, Map<String, String>>> list = new ArrayList<Map<String, Map<String, String>>>();
		list.add(auditDate);
		requestBody.put(SORT, list);
		if (size > 0) {
			requestBody.put(SIZE, size);
		}

		requestBody.put(QUERY, buildQuery(mustFilter, mustNotFilter, shouldFilter, searchText, mustTermsFilter,null));
		requestBody.put(_SOURCE, fields);
		Gson serializer = new GsonBuilder().create();
		String request = serializer.toJson(requestBody);
		String responseDetails = null;
		try {
			responseDetails = PacHttpUtils.doHttpPost(urlToQuery, request);
			serializer = new GsonBuilder().create();
			Map<String, Object> response = (Map<String, Object>) serializer.fromJson(responseDetails, Object.class);
			if (response.containsKey(HITS)) {
				Map<String, Object> hits = (Map<String, Object>) response.get(HITS);
				if (hits.containsKey(HITS)) {
					List<Map<String, Object>> hitDetails = (List<Map<String, Object>>) hits.get(HITS);
					if (!hitDetails.isEmpty()) {
						for (Map<String, Object> hitDetail : hitDetails) {
							Map<String, Object> sources = (Map<String, Object>) hitDetail.get(_SOURCE);
							results.add(CommonUtils.flatNestedLinkedHashMap(null, sources));

						}
					} else {
						throw new RuntimeException(NO_RECORDS_FOUND);
					}
				}
			}
		} catch (Exception e) {
			LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e);
			throw e;
		}
		return results;
	}

}