# Range query through custom window time

**URL:** <https://discuss.elastic.co/t/range-query-through-custom-window-time/267428>\
**Category:** Elasticsearch\
**Created:** [March 16, 2021, 10:58pm UTC](https://discuss.elastic.co/t/range-query-through-custom-window-time/267428 "2021-03-16T22:58:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcosvrrs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcosvrrs/32/77073_2.png) [@marcosvrrs](https://discuss.elastic.co/u/marcosvrrs)\
**Post date:** [March 16, 2021, 10:58pm UTC](https://discuss.elastic.co/t/range-query-through-custom-window-time/267428/1 "2021-03-16T22:58:00Z")

</div>

I have this query in Dev Tools that I do when my boss asks that counts how many cards were used in 90 days window:

```
GET transactions/_search
{
  "size": 0,
  "query": {
"range": {
  "timestamp": {
    "gte": "now-90d/d",
    "lte": "now"
  }
}
  },
  "aggs": {
    "by_client": {
      "terms": {
        "field": "clients.keyword"
      },
      "aggs": {
        "active_cards": {
          "cardinality": {
            "field": "card_number.keyword"
          }
        }
      }
    }
  }
}
  }
}

```

I need to run this for every month of my data that we have (about 3 years), so I can show in a Dashboard (example of buckets: 2021-03-01 to 2020-12-01, going back 2021-02-01 to 2020-11-01, and so on).  
I will gladly give more information, but I am having some difficult to synthesize the idea.

Thank you guys in advance!

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 16, 2021, 11:48pm UTC](https://discuss.elastic.co/t/range-query-through-custom-window-time/267428/2 "2021-03-16T23:48:14Z")

</div>

Something like this?

> **[Moving function aggregation | Elasticsearch Reference \[7.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-aggregations-pipeline-movfn-aggregation.html)**

---

<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:** [April 13, 2021, 11:48pm UTC](https://discuss.elastic.co/t/range-query-through-custom-window-time/267428/3 "2021-04-13T23:48:32Z")

</div>

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