gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 脚本中从日期获取时间戳

转载 作者:行者123 更新时间:2023-12-02 22:48:21 25 4
gpt4 key购买 nike

就像标题所暗示的那样,我想从 flex 搜索无痛脚本中的日期类型获取时间戳(作为数字)。下列尝试无效:doc["date_field"].valuedoc["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

关于elasticsearch - 如何在 Elasticsearch 脚本中从日期获取时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52853856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com