Elasticsearch giving warning for painless script


(Shubham Mahajan) #1

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????


Trying to apply filter on scripted field
(Ryan Ernst) #2

You need to replace .date with .value.


(Shubham Mahajan) #3

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

(Shubham Mahajan) #4

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


Trying to apply filter on time-difference scripted field
(system) #5

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