如何在弹性搜索脚本中从日期获取时间戳
How to get timestamp from date in elastic search script
如标题所示,我想从弹性搜索无痛脚本中的日期类型获取时间戳(作为数字)。以下尝试无效:doc["date_field"].value
、doc["date_field"].date.getMillis()
.
根据 Painless docs,您应该能够像这样访问自纪元以来的毫秒数:doc.date_field.millis
。
Date fields are exposed as ReadableDateTime
, so they support methods
like getYear
, getDayOfWeek
or e.g. getting milliseconds since epoch
with getMillis
. To use these in a script, leave out the get prefix and
continue with lowercasing the rest of the method name.
您应该也可以使用 ReadableDateTime
中的方法。 https://www.elastic.co/guide/en/elasticsearch/painless/6.4/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime
如标题所示,我想从弹性搜索无痛脚本中的日期类型获取时间戳(作为数字)。以下尝试无效:doc["date_field"].value
、doc["date_field"].date.getMillis()
.
根据 Painless docs,您应该能够像这样访问自纪元以来的毫秒数:doc.date_field.millis
。
Date fields are exposed as
ReadableDateTime
, so they support methods likegetYear
,getDayOfWeek
or e.g. getting milliseconds since epoch withgetMillis
. To use these in a script, leave out the get prefix and continue with lowercasing the rest of the method name.
您应该也可以使用 ReadableDateTime
中的方法。 https://www.elastic.co/guide/en/elasticsearch/painless/6.4/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime