Kibana脚本脚本使用无痛的字段:如何使用先前索引来查找过去的天数

发布于 2025-02-13 17:58:24 字数 498 浏览 2 评论 0原文

我有一堆Kibana的数据,需要使用带有“无痛”的脚本字段来清理,这是Java的一种版本。目前,我的日志中有一个以这种格式的日期“ 2021-09-27T13:54:17.165Z” 我需要找到自那天以来已经有多少天了 则需要返回错误。

运行,如果它的结束或300天时, new Date()。getTime() - doc ['date']。value;

i在堆栈溢出上,我看到有人说新的date()。getTime()将为您提供今天的日期。但是我认为问题是时间格式 for new Date()。getTime(GetTime()以1657151078131的格式返回时间,但我的索引日期在“ 2021-09-27T13:54:17.165Z”中“ 我不确定如何转换它以找到较少或超过300天的位移。

任何帮助都将不胜感激

#elk #elasticsearch #kibana#弹性

I have a bunch of data in Kibana that I need to clean up by using an scripted field with "painless" which is a version of Java. At the moment I have an preexisting index in my logs with a date in this format "2021-09-27T13:54:17.165Z" I need to find how many days its been since that day until today whenever this search is ran, if its over or at 300 days it needs to return false if its lower true.

I was trying this to get number of days its been:
new Date().getTime() - doc['date'].value;

I was on stack overflow I saw someone said that new Date().getTime() will give you todays date. But I think the issue is that the time format for new Date().getTime() returns time in the format of 1657151078131 but my index date is in "2021-09-27T13:54:17.165Z" I am not sure how to convert it in order to find the displacement of less or more than 300 days.

Any help will be greatly appreciated

#ELK #elasticsearch #kibana #elastic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2025-02-20 17:58:24

tldr;

您有一个转换所有内容的问题。
new Date()。getTime() - >给了很长时间
“ 2021-09-27T13:54:17.165Z” - >一个绳子

来解决

您需要将它们移动到相同的格式。
在下面,我将String格式的日期转换为ZonedDateTime,然后转换为long

new Date().getTime() - ZonedDateTime.parse("2021-09-27T13:54:17.165Z").toInstant().toEpochMilli() > 25920000000L;

这是一种方法。
您可以了解更多有关无痛和时间格式

Tldr;

You have an issue converting everything.
new Date().getTime() -> gives a Long
"2021-09-27T13:54:17.165Z" -> a string

To Solve

You need to make move them to the same format.
Below I am converting the date in a string format to a ZonedDateTime then to a long.

new Date().getTime() - ZonedDateTime.parse("2021-09-27T13:54:17.165Z").toInstant().toEpochMilli() > 25920000000L;

That one way to go about it.
You can learn more about painless and time formats here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文