# Elasticsearch giving warning for painless script

**URL:** <https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030>\
**Category:** Elasticsearch\
**Created:** [December 22, 2017, 3:41pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030 "2017-12-22T15:41:59Z")\
**Posts on this page:** 5\
**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:** [December 22, 2017, 3:41pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/1 "2017-12-22T15:41:59Z")

</div>

Hi team,  
I have a question regarding Date API. As you can see in the below script, i am trying to subtract two dates. As this script does give me the result but with that it's also giving me a `Deprecation warning`.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/2/a2406dd7bba79d44b405acaee093797547c26639.png)

but when i remove the `.Date` from the script, then it's giving me an error. Could u explain What the warning is about????

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

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 22, 2017, 7:46pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/2 "2017-12-22T19:46:23Z")

</div>

You need to replace `.date` with `.value`.

---

<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:** [December 23, 2017, 12:42pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/3 "2017-12-23T12:42:26Z")

</div>

@rjernst Thanks a lot, Ryan.

Also i have been facing another problem with ES. It's giving me timeout errors.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ae4632f80c10eb31f71b890ea384c3ae717af65.png)

Request being fired in data table visual is below. But this timeout issue is happening if time interval is increased from `1h`. Actually here i am using scripted field, but when fire the same request for `@timestamp` field it doesn't give any error. Could u please provide ur insight ??

```
{
  "size": 0,
  "aggs": {
    "2": {
      "terms": {
        "field": "host.keyword",
        "size": 20,
        "order": {
          "1": "desc"
        }
      },
      "aggs": {
        "1": {
          "min": {
            "script": {
              "source": "new Date().getTime() - doc['@timestamp'].value.getMillis()",
              "lang": "painless"
            }
          }
        }
      }
    }
  },
  "script_fields": {
    "time-diff": {
      "script": {
        "source": "new Date().getTime() - doc['@timestamp'].value.getMillis()",
        "lang": "painless"
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "match_all": {}
        },
        {
          "match_phrase": {
            "host": {
              "query": "frm-*"
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "now-1d",
              "format": "epoch_millis"
            }
          }
        }
      ]
    }
  }
}
```

---

<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:** [December 23, 2017, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/4 "2017-12-23T13:28:04Z")

</div>

@rjernst Hey Ryan, for my last question, when i changed `.date` to `.value` the timeout issue was resolved. Thanks a lot, man.  
But out of curiosity, what's the reason behind this issue when using `.date` in scripted fields.

---

<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:** [January 20, 2018, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-giving-warning-for-painless-script/113030/5 "2018-01-20T13:28:09Z")

</div>

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