Access the epoch of the date type doc in groovy script

As per my understanding and from here [http://stackoverflow.com/questions/29341715/understanding-how-elasticsearch-stores-dates-internally] (http://stackoverflow.com/questions/29341715/understanding-how-elasticsearch-stores-dates-internally) ealstic search stores the date internally as epoch format. Now consider I need to access this epoch in groovy script and out doc date format is date_optional_time. Now when I try to access it in groovy script it gives me the formatted date(as on the time of input). Is there a way to access the epoch time here.
I have come up with three thoughts

  1. Convert the doc value to date and get millis in script,
  2. Create a new field with copy_to that stores the date as epoch format
    3)//or if possible directly access the epoch. but how?

Can some body guide me on this.I need epoch because I need to update some other field on basis of the epoch

e.g
Consider a mapping like this
{
"createdDate": {
"type": "date",
"store": true,
"format": "dateOptionalTime"
}
"modifiedDate": {
"type": "date",
"store": true,
"format": "dateOptionalTime"
}
"daysINBetween" : {
"type" : "long"
}
,
}

Now I need to run a script that stores (createdDate.millis - modifiedDate.millis) / (24 * 60 * 60 * 1000). I don't want to create a new object of date each time, that's why I am trying to access epoch in script

http://stackoverflow.com/questions/37877534/access-epoch-from-date-field-in-groovy-script-in-elastic-search

Hey,

try doc['createdDate'].date.getMillis()

I would try to do calculate this on index time, instead of query time though, in order to have faster queries.

--Alex

As per my knowledge doc['createdDate'].date.getMillis() will be accessible in script_field only.Am I right?