# Count field value by date range

**URL:** <https://discuss.elastic.co/t/count-field-value-by-date-range/234659>\
**Category:** Kibana\
**Created:** [May 28, 2020, 5:49am UTC](https://discuss.elastic.co/t/count-field-value-by-date-range/234659 "2020-05-28T05:49:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_H](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@Jose\_H](https://discuss.elastic.co/u/Jose_H)\
**Post date:** [May 28, 2020, 5:49am UTC](https://discuss.elastic.co/t/count-field-value-by-date-range/234659/1 "2020-05-28T05:49:43Z")

</div>

Hi,

Is it possible to have a count of data of a specific field for the past 7 days?

**Query:**

> GET /my-index/\_count?q=my-field:\*

**Results:**

> {  
> "count" : 438,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "skipped" : 0,  
> "failed" : 0  
> }  
> }

The above query is showing results for all dates.

---

<div class="post-metadata">

**Author:** ![Jose\_H](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@Jose\_H](https://discuss.elastic.co/u/Jose_H)\
**Post date:** [May 28, 2020, 12:01pm UTC](https://discuss.elastic.co/t/count-field-value-by-date-range/234659/2 "2020-05-28T12:01:16Z")

</div>

Solution found. Hope it manages to help someone out:

```
GET /my-index/_search
{
  "query": {
    "bool" : {
      "must" : {
        "wildcard" : { "my-field": "*" }
      },
     "filter": 
        {
          "range": {
            "@timestamp": {
               "gte": "now-7d",
               "lte": "now"
            }
          }
        }
    }
  }
}
```

---

<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:** [June 25, 2020, 12:01pm UTC](https://discuss.elastic.co/t/count-field-value-by-date-range/234659/3 "2020-06-25T12:01:17Z")

</div>

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