lxneng lxneng - 1 year ago 142
Groovy Question

how to convert date type field data to unixtimestamp in elasticsearch

in es,

as a date type

created_at: {
type: "date",
format: "strict_date_optional_time||epoch_millis"

i want use created_at as a UnixTimeStamp epoch seconds in
calculation. how to implement this?

(doc['created_at'].value.to_unixtimestamp? - 1412092800)/86400.0

Val Val
Answer Source

You have two options, either like this

((doc['created_at'].value / 1000) - 1412092800)/86400.0

or like this:

((doc['created_at'].date.millis / 1000) - 1412092800)/86400.0