class ElasticSearchRepository implements Constants {

	public List<Map<String, Object>> getUtilizationByAssetGroup(String asseGroup) throws Exception {
		String urlToQuery = buildAggsURL(esUrl, asseGroup, EC2_UTILIZATION);
		Map<String, Object> requestBody = new HashMap<String, Object>();
		Map<String, Object> cpuUtilizationDetails = new HashMap<String, Object>();
		Map<String, Object> cpuUtilization = new HashMap<String, Object>();
		Map<String, Object> range = new HashMap<String, Object>();
		Map<String, Object> must = new HashMap<String, Object>();
		Map<String, Object> bool = new HashMap<String, Object>();
		Map<String, Object> aggs = new HashMap<String, Object>();
		Map<String, Object> histogram = new HashMap<String, Object>();
		Map<String, Object> histogramDetails = new HashMap<String, Object>();
		Map<String, Object> avgValuesperDay = new HashMap<String, Object>();
		List<Map<String, Object>> utilizationList = new ArrayList<Map<String, Object>>();
		Map<String, Object> utilization = null;
		Map<String, Object> field = null;
		Map<String, Object> sum = null;
		Map<String, Object> avg = null;
		// must Query formate
		cpuUtilizationDetails.put("gte", "now-30d");
		cpuUtilizationDetails.put("lte", "now-1d");
		cpuUtilizationDetails.put("format", "yyyy-MM-dd HH:mm:ss");
		cpuUtilization.put("#Datetime-CPU-Utilization", cpuUtilizationDetails);
		range.put(RANGE, cpuUtilization);
		must.put(MUST, range);
		bool.put(BOOL, must);
		// Aggs Query foramte

		field = new HashMap();
		avg = new HashMap();
		field.put("field", AVG_CPU_UTILIZATION);
		avg.put(AVG, field);
		aggs.put(AVG_CPU_UTILIZATION, avg);

		field = new HashMap();
		sum = new HashMap();
		field.put("field", SUM_NETWORK_IN);
		sum.put(SUM, field);
		aggs.put("Avg-NetworkIn", sum);

		field = new HashMap();
		sum = new HashMap();
		field.put("field", SUM_NETWORK_OUT);
		sum.put(SUM, field);
		aggs.put("Avg-NetworkOut", sum);

		field = new HashMap();
		sum = new HashMap();
		field.put("field", "Sum-DiskReadBytes");
		sum.put(SUM, field);
		aggs.put("Avg-DiskReadinBytes", sum);

		field = new HashMap();
		sum = new HashMap();
		field.put("field", "Sum-DiskWriteBytes");
		sum.put(SUM, field);
		aggs.put("Avg-DiskWriteinBytes", sum);

		field = new HashMap();
		field.put("_key", "desc");
		histogramDetails.put("field", "#Datetime-CPU-Utilization");
		histogramDetails.put("interval", "day");
		histogramDetails.put("format", "yyyy-MM-dd HH:mm:ss");
		histogramDetails.put(ORDER, field);
		histogram.put("date_histogram", histogramDetails);
		histogram.put(AGGS, aggs);
		avgValuesperDay.put("avg-values-per-day", histogram);

		requestBody.put(QUERY, bool);
		requestBody.put(AGGS, avgValuesperDay);
		requestBody.put(SIZE, 0);

		Gson gson = new GsonBuilder().create();

		try {
			String request = gson.toJson(requestBody, Object.class);
			String responseDetails = null;

			responseDetails = PacHttpUtils.doHttpPost(urlToQuery, request);

			JsonParser parser = new JsonParser();
			JsonObject responseDetailsjson = parser.parse(responseDetails).getAsJsonObject();
			responseDetailsjson.get("aggregations");
			Object aggregations = responseDetailsjson.get("aggregations");
			String aggregationsstr = aggregations.toString();
			parser = new JsonParser();
			JsonObject aggregationsjson = (JsonObject) parser.parse(aggregationsstr);
			Object avgvalues = aggregationsjson.get("avg-values-per-day");
			String avgvaluestr = avgvalues.toString();
			parser = new JsonParser();
			JsonObject avgvaluesjson = (JsonObject) parser.parse(avgvaluestr);
			Object bucketObj = avgvaluesjson.get(BUCKETS);
			String bucketstr = bucketObj.toString();
			parser = new JsonParser();
			JsonArray buckets = parser.parse(bucketstr).getAsJsonArray();

			for (JsonElement jsonElement : buckets) {
				utilization = new HashMap<String, Object>();

				JsonObject bucketdetails = jsonElement.getAsJsonObject();
				utilization.put(DATE, bucketdetails.get("key_as_string").getAsString());

				Object cpuUtilizationObj = bucketdetails.get(AVG_CPU_UTILIZATION);
				String cpuUtilizationStr = cpuUtilizationObj.toString();
				parser = new JsonParser();
				JsonObject cpuUtilizationjson = (JsonObject) parser.parse(cpuUtilizationStr);
				if (!cpuUtilizationjson.get("value").isJsonNull()) {
					utilization.put(CPU_UTILIZATION, cpuUtilizationjson.get("value").getAsDouble());
				} else {
					utilization.put(CPU_UTILIZATION, 0);
				}
				Object networkInUtilizationObj = bucketdetails.get("Avg-NetworkIn");
				String networkInUtilizationStr = networkInUtilizationObj.toString();
				parser = new JsonParser();
				JsonObject networkInUtilizationjson = (JsonObject) parser.parse(networkInUtilizationStr);
				if (!networkInUtilizationjson.get("value").isJsonNull()) {
					utilization.put(NETWORK_IN, networkInUtilizationjson.get("value").getAsLong());
				} else {
					utilization.put(NETWORK_IN, 0);
				}
				Object networkOutUtilizationObj = bucketdetails.get("Avg-NetworkOut");
				String networkOutUtilizationStr = networkOutUtilizationObj.toString();
				parser = new JsonParser();
				JsonObject networkOutUtilizationjson = (JsonObject) parser.parse(networkOutUtilizationStr);
				if (!networkOutUtilizationjson.get("value").isJsonNull()) {
					utilization.put(NETWORK_OUT, networkOutUtilizationjson.get("value").getAsLong());
				} else {
					utilization.put(NETWORK_OUT, 0);
				}
				Object diskReadUtilizationObj = bucketdetails.get("Avg-DiskReadinBytes");
				String diskReadUtilizationStr = diskReadUtilizationObj.toString();
				parser = new JsonParser();
				JsonObject diskReadUtilizationjson = (JsonObject) parser.parse(diskReadUtilizationStr);
				if (!diskReadUtilizationjson.get("value").isJsonNull()) {
					utilization.put(DISK_READ_IN_BYTES, diskReadUtilizationjson.get("value").getAsLong());
				} else {
					utilization.put(DISK_READ_IN_BYTES, 0);
				}
				Object diskRWriteUtilizationObj = bucketdetails.get("Avg-DiskWriteinBytes");
				String diskRWriteUtilizationStr = diskRWriteUtilizationObj.toString();
				parser = new JsonParser();
				JsonObject diskRWriteUtilizationjson = (JsonObject) parser.parse(diskRWriteUtilizationStr);
				if (!diskRWriteUtilizationjson.get("value").isJsonNull()) {
					utilization.put(DISK_WRITE_IN_BYTES, diskRWriteUtilizationjson.get("value").getAsLong());
				} else {
					utilization.put(DISK_WRITE_IN_BYTES, 0);
				}
				utilizationList.add(utilization);
			}
			return utilizationList;

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

}