# Search based on runtime boolean calculated from now

**URL:** <https://discuss.elastic.co/t/search-based-on-runtime-boolean-calculated-from-now/299488>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [March 11, 2022, 7:14pm UTC](https://discuss.elastic.co/t/search-based-on-runtime-boolean-calculated-from-now/299488 "2022-03-11T19:14:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkAllan](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@MarkAllan](https://discuss.elastic.co/u/MarkAllan)\
**Post date:** [March 11, 2022, 7:14pm UTC](https://discuss.elastic.co/t/search-based-on-runtime-boolean-calculated-from-now/299488/1 "2022-03-11T19:14:07Z")

</div>

I need to be able to search on a field that is not part of the stored document but is derived from a field on that document.

The document field is a timestamp called expiry\_utc\_timestamp. I need to be able to filter on a field called isexpired that is not part of the document. It is a boolean that will be true or false depending on the time of the query (i.e. now) and the static expiry\_utc\_timestamp value.

I tried creating a runtime field as follows:

```auto
POST messages/_mapping
{
  "runtime": {
    "isexpired": {
        "type": "boolean",
        "script": {
          "source": "emit(doc['expiry_utc_timestamp'].value <= now)"
        }
      }
  }
}

```

But this is not a valid request. It appears that the painless scripting does not provide the use of now.

Please can someone advise on how I can achieve searching on a runtime field that is not part of the actual document where this field is calculated taking into account the current date & time.

I cannot filter on "expiry\_utc\_timestamp \> now" without making large architectural changes to my application code. I need to be able to filter on "isexpired:true" or "isexpired:false".

---

<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 8, 2022, 7:14pm UTC](https://discuss.elastic.co/t/search-based-on-runtime-boolean-calculated-from-now/299488/2 "2022-04-08T19:14:11Z")

</div>

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