# Elasticsearch aggregation on array field with in a range

**URL:** <https://discuss.elastic.co/t/elasticsearch-aggregation-on-array-field-with-in-a-range/290031>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [November 24, 2021, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-on-array-field-with-in-a-range/290031 "2021-11-24T09:16:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiajun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiajun/32/78942_2.png) [@jiajun](https://discuss.elastic.co/u/jiajun)\
**Post date:** [November 24, 2021, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-on-array-field-with-in-a-range/290031/1 "2021-11-24T09:16:16Z")

</div>

I'm going to perform a count aggregation on an array field by filtering the values in a range. For example, I have following 3 documents and I want to find out value counts for purchase\_date\_list that are between 20210101 to now(). The expected result (purchase count between 20210101 - now()) will be that: customer\_id: 1, purchase count is: 2 customer\_id: 2, purchase count is: 0 customer\_id: 3, purchase count is: 1

Can anybody please help with some ideas on how to compose a aggregation query for above request?

Many thanks!

```auto
{
  customer_id: 1,
  purchase_date_list: [
    20050101,
    20210304,
    20211121
  ]
},
{
  customer_id: 2,
  purchase_date_list: [
    20100301
  ]
},
{
  customer_id: 3,
  purchase_date_list: [
    20210701
  ]
}

```

---

<div class="post-metadata">

**Author:** ![jiajun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiajun/32/78942_2.png) [@jiajun](https://discuss.elastic.co/u/jiajun)\
**Post date:** [November 29, 2021, 1:35pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-on-array-field-with-in-a-range/290031/2 "2021-11-29T13:35:05Z")

</div>

looking forward for feedbacks!

---

<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:** [December 27, 2021, 1:35pm UTC](https://discuss.elastic.co/t/elasticsearch-aggregation-on-array-field-with-in-a-range/290031/3 "2021-12-27T13:35:37Z")

</div>

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