# Using "now" in bucket\_selector script

**URL:** <https://discuss.elastic.co/t/using-now-in-bucket-selector-script/135919>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 1:10pm UTC](https://discuss.elastic.co/t/using-now-in-bucket-selector-script/135919 "2018-06-14T13:10:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![R.Rabbit](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@R.Rabbit](https://discuss.elastic.co/u/R.Rabbit)\
**Post date:** [June 14, 2018, 1:10pm UTC](https://discuss.elastic.co/t/using-now-in-bucket-selector-script/135919/1 "2018-06-14T13:10:28Z")

</div>

Hey there,

I want to get the entities that showed up in the last 24h and suppressing all those that had appeared earlier. The query looks like: \> {

> ```
> {
> "aggs": {
> "entity" : {
> "terms" : {
> "field" : "name"
> },
> "aggs" : {
> "first_seen" : {
> "min" : {
> "field" : "@timestamp"
> }
> },
> "time_filter" : {
> "bucket_selector" : {
> "buckets_path" : "first_seen",
> "script" : "params.first_seen > now -1d"
> }
> }
> }
> }
> }
> }
> 
> ```

But,I dont know how to include the current date in the script. I tried to pass it as an additional parameters to the script, however, without success.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 22, 2018, 5:55pm UTC](https://discuss.elastic.co/t/using-now-in-bucket-selector-script/135919/2 "2018-06-22T17:55:09Z")

</div>

I think a better approach is to use a `filter` aggregation in between the "entity" and "first\_seen" agg. Just filter the timestamp with a range query, and it will naturally only show "first\_seen" buckets that have a value \> the filter.

---

<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 20, 2018, 5:55pm UTC](https://discuss.elastic.co/t/using-now-in-bucket-selector-script/135919/3 "2018-07-20T17:55:11Z")

</div>

Closed on July 20, 2018, 5:55pm UTC

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