# Include 6 Month record counts in buckets with monthly counts

**URL:** <https://discuss.elastic.co/t/include-6-month-record-counts-in-buckets-with-monthly-counts/185347>\
**Category:** Elasticsearch\
**Created:** [June 12, 2019, 7:20am UTC](https://discuss.elastic.co/t/include-6-month-record-counts-in-buckets-with-monthly-counts/185347 "2019-06-12T07:20:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pramod.kumar2](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@pramod.kumar2](https://discuss.elastic.co/u/pramod.kumar2)\
**Post date:** [June 12, 2019, 7:20am UTC](https://discuss.elastic.co/t/include-6-month-record-counts-in-buckets-with-monthly-counts/185347/1 "2019-06-12T07:20:09Z")

</div>

Hi,

I am using ElasticSearch 6.2 and I have one query to get record counts for Monthly data for particular period. I want to include 6 Month data record count in same bucket whereas 6 Months should not consider current month.

Can you please help me to find a way to get Last 6 Month counts from current month bucket. For example - If monthly data is for Feb-2019, then last 6 Month data count I want is from Aug-2018 to Jan-2019(Means leave Feb-2019) and if monthly data is for April-2019 then 6 month count required will be from Oct-2018 to Mar-2019.

Below is the sample code which currently I am using for getting monthly aggregation portwise -

```
{ 
  "aggs": {
  "GroupByPortId": {
		"terms": {
			"field": "portId",
			"size": 10000
		},
		"aggs": {
			"LocalPortBuckets": {
				"date_histogram": {
					"field": "date",
					"interval": "month",
					"min_doc_count": 0,
					"order": {
						"_key": "desc"
					},
					"extended_bounds": {
						"min": null,
						"max": null
					}
				}
			}
		}
	}
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 10, 2019, 7:20am UTC](https://discuss.elastic.co/t/include-6-month-record-counts-in-buckets-with-monthly-counts/185347/2 "2019-07-10T07:20:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
