Elasticsearch giving warning for painless script

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.

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

You need to replace .date with .value.

@rjernst Thanks a lot, Ryan.

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

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"
            }
          }
        }
      ]
    }
  }
}

@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.

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