# Count values within an element created today

**URL:** https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901
**Category:** Elasticsearch
**Created:** [October 30, 2019, 3:48pm UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901 "2019-10-30T15:48:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fernrguez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fernrguez/32/54799_2.png) [@fernrguez](https://discuss.elastic.co/u/fernrguez)
#### Post date: [October 30, 2019, 3:48pm UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901/1 "2019-10-30T15:48:39Z")

</div>

Hi all,

I'm trying to create a query to retrieve a list of elements that indicates the number of appearance for current day.  
For example, I have logs with logLevel that could be ERROR, INFO, WARN, ..

So far I have this, but what I'm not able to do is just display the ones from current day

```
	"aggs": {
		"count" : {
			"terms" : {
				"field" : "logLevel.keyword"
			}
		}
	}

```

Result from the query above

```
  ... },
  "aggregations" : {
    "count" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "INFO",
          "doc_count" : 311355
        },
        {
          "key" : "WARN",
          "doc_count" : 26441
        },
        {
          "key" : "ERROR",
          "doc_count" : 15065
        }
      ]
    }
  }
}

```

How can I filter the query in order to get just the number of records generated during current day?

Thanks in advance

---

<div class="post-metadata">

### Author: ![Segfault](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Segfault](https://discuss.elastic.co/u/Segfault)
#### Post date: [October 30, 2019, 3:52pm UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901/2 "2019-10-30T15:52:07Z")

</div>

You should use range filter, here is a sample (you will have to adapt it to your needs, this is one will filter on documents created on the last 7 days)

```
"filter": [{
    "range" : {
        "@timestamp" : {
            "gte": "now-7d/d",
            "lte": "now/d"
        }
    }
}]
```

---

<div class="post-metadata">

### Author: ![fernrguez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fernrguez/32/54799_2.png) [@fernrguez](https://discuss.elastic.co/u/fernrguez)
#### Post date: [October 30, 2019, 4:13pm UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901/3 "2019-10-30T16:13:46Z")

</div>

I'm a bit clumsy, would it be possible to show me how it would be the correct way to add the filter?  
I'm trying several posibilities with no luck.

---

<div class="post-metadata">

### Author: ![fernrguez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fernrguez/32/54799_2.png) [@fernrguez](https://discuss.elastic.co/u/fernrguez)
#### Post date: [October 31, 2019, 8:50am UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901/4 "2019-10-31T08:50:37Z")

</div>

I'm trying with this query but somehow is not returning values and I can't find the reason

```
POST _search?size=0
{
  "aggs": {
    "docs": {
      "filter": {
        "range": {
          "eventTimestamp" : {
              "lt" : "2019-10-29 00:00:00",
              "gte" : "2019-10-29 23:59:59"
          }
        }
      },
      "aggs": {
        "count": {
          "terms": {
            "field": "logLevel.keyword"
          }
        }
      }
    }
  }
}
```

---

<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: [November 28, 2019, 8:50am UTC](https://discuss.elastic.co/t/count-values-within-an-element-created-today/205901/5 "2019-11-28T08:50:37Z")

</div>

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