Define a date variable with an initial value in scripted field

Hi,
I'm working with an scripted field that computes a difference between two dates

 "total_duration": {
                      "max": {
                        "script": {"source": "(doc['ts_stop'].value - doc['ts_start'].value)/1000"}
                      }
                    }

But now instead of using the value of the field ts_start I want to use a fixed value (for example 2017-11-11T00:28:00.000Z)
How do I define a variable of type date holding that value in order to change the script file to something like this

"script": {"source": "(doc['ts_stop'].value - new_var)/1000"}

Thank you very much
Regards
Anna

Why not use externalized parameters:

   {"source": ""(doc['ts_stop'].value - new_var)/1000"",
    "params": {
      "new_var": 123
    }

?

Thank you @costin.
It think that this approach should work for me.
I have replaced my code with

"script": {"source": "(doc['ts_stop'].value - new_var)/1000", "params": {"new_var": 1510358400000}}

But I get

 "script": "(doc['ts_stop'].value - new_var)/1000",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Variable [new_var] is not defined."
          }

I'll try to figure out what is wrong.
Regards
Anna

Try (doc['ts_stop'].value - params.new_var)/1000.

By the way, the syntax is explained here

Thank you very much @costin
Worked ok!

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