# Trying to apply filter on time-difference scripted field

**URL:** <https://discuss.elastic.co/t/trying-to-apply-filter-on-time-difference-scripted-field/117025>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 10:49am UTC](https://discuss.elastic.co/t/trying-to-apply-filter-on-time-difference-scripted-field/117025 "2018-01-25T10:49:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shubham\_Mahajan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubham_mahajan/32/22140_2.png) [@Shubham\_Mahajan](https://discuss.elastic.co/u/Shubham_Mahajan)\
**Post date:** [January 25, 2018, 10:49am UTC](https://discuss.elastic.co/t/trying-to-apply-filter-on-time-difference-scripted-field/117025/1 "2018-01-25T10:49:19Z")

</div>

Continuing the discussion from [Elasticsearch giving warning for painless script](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/4):

`time-diff: new Date().getTime() - doc['@timestamp'].value.getMillis()`

@rjernst hey Ryan, I need some urgent help regarding this functioning. Using above scripted field I am displaying hosts with their last communication time.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/7/c758f839b726d6d873c6eaad59a2c7d124aead96.png)

But now i just want to display the hosts with time difference greater than, let's say, 7 days only.  
Is there any way to compare the `time-diff` scripted field and only display those hosts that have not sent events for few days, in this case.

Really appreciate your help!!

---

<div class="post-metadata">

**Author:** ![Shubham\_Mahajan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubham_mahajan/32/22140_2.png) [@Shubham\_Mahajan](https://discuss.elastic.co/u/Shubham_Mahajan)\
**Post date:** [January 30, 2018, 2:35pm UTC](https://discuss.elastic.co/t/trying-to-apply-filter-on-time-difference-scripted-field/117025/2 "2018-01-30T14:35:09Z")

</div>

@rjernst Hey Ryan, is there any solution to this problem??

---

<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:** [February 27, 2018, 2:35pm UTC](https://discuss.elastic.co/t/trying-to-apply-filter-on-time-difference-scripted-field/117025/3 "2018-02-27T14:35:31Z")

</div>

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