Kibana 中的日期差异脚本字段
Date difference scripted field in Kibana
我想使用脚本字段找出两个字段之间的区别。以下是两个日期字段及其格式:
start_time - June 17th 2018, 09:44:46.000
end_time - June 17th 2018, 09:44:49.000
这将给出 proc_time
。
这是我在脚本字段中尝试做的事情:
doc['start_time'].date.millis - doc['end_time'].date.millis
但这是返回从纪元时间中扣除的处理时间。
比如我的处理时间是2秒,那么输出就是epoch time - 2 seconds
。
这不是我想要的。
这是示例文档:
17 Jun 2018 04:14:46 INFO CSG event file generation started at: Sun Jun 17 04:14:46 CDT 2018
17 Jun 2018 04:14:46 INFO Executing CSG file generation process
Warning: Using a password on the command line interface can be insecure.
17 Jun 2018 04:15:57 INFO Finished at: Sun Jun 17 04:15:57 CDT 2018
任何帮助将不胜感激。
更新
我已经使用以下无痛脚本进行了此操作:
((doc['csg_proc_end_time'].date.year) * 31536000 + doc['csg_proc_end_time'].date.monthOfYear * 86400 + doc['csg_proc_end_time'].date.dayOfMonth * 3600 + doc['csg_proc_end_time'].date.secondOfDay) - ((doc['csg_proc_start_time'].date.year) * 31536000 + doc['csg_proc_start_time'].date.monthOfYear * 86400 + doc['csg_proc_start_time'].date.dayOfMonth * 3600 + doc['csg_proc_start_time'].date.secondOfDay)
但是,我欢迎任何其他以更简单的方式执行此操作的脚本。
JSON 添加字段的格式:
"fields": {
"@timestamp": [
"2018-06-20T04:45:00.258Z"
],
"zimbra_proc_time": [
0
],
"csg_proc_time": [
71
],
"perftech_proc_time": [
0
],
"csg_proc_end_time": [
"2018-06-17T04:15:57.000Z"
],
"csg_proc_start_time": [
"2018-06-17T04:14:46.000Z"
]
},
这就是我为重现您的问题所做的工作,它工作正常:
PUT test/doc/1
{
"csg_proc_end_time": "2018-06-17T04:15:57.000Z",
"csg_proc_start_time": "2018-06-17T04:14:46.000Z"
}
现在计算脚本字段中的处理时间:
GET test/_search
{
"script_fields": {
"proc_time": {
"script": {
"source": "(doc.csg_proc_end_time.value.millis - doc.csg_proc_start_time.value.millis) / 1000"
}
}
}
}
结果:71 秒
{
"_index": "test",
"_type": "doc",
"_id": "1",
"_score": 1,
"fields": {
"proc_time": [
71
]
}
}
我想使用脚本字段找出两个字段之间的区别。以下是两个日期字段及其格式:
start_time - June 17th 2018, 09:44:46.000
end_time - June 17th 2018, 09:44:49.000
这将给出 proc_time
。
这是我在脚本字段中尝试做的事情:
doc['start_time'].date.millis - doc['end_time'].date.millis
但这是返回从纪元时间中扣除的处理时间。
比如我的处理时间是2秒,那么输出就是epoch time - 2 seconds
。
这不是我想要的。
这是示例文档:
17 Jun 2018 04:14:46 INFO CSG event file generation started at: Sun Jun 17 04:14:46 CDT 2018
17 Jun 2018 04:14:46 INFO Executing CSG file generation process
Warning: Using a password on the command line interface can be insecure.
17 Jun 2018 04:15:57 INFO Finished at: Sun Jun 17 04:15:57 CDT 2018
任何帮助将不胜感激。
更新
我已经使用以下无痛脚本进行了此操作:
((doc['csg_proc_end_time'].date.year) * 31536000 + doc['csg_proc_end_time'].date.monthOfYear * 86400 + doc['csg_proc_end_time'].date.dayOfMonth * 3600 + doc['csg_proc_end_time'].date.secondOfDay) - ((doc['csg_proc_start_time'].date.year) * 31536000 + doc['csg_proc_start_time'].date.monthOfYear * 86400 + doc['csg_proc_start_time'].date.dayOfMonth * 3600 + doc['csg_proc_start_time'].date.secondOfDay)
但是,我欢迎任何其他以更简单的方式执行此操作的脚本。
JSON 添加字段的格式:
"fields": {
"@timestamp": [
"2018-06-20T04:45:00.258Z"
],
"zimbra_proc_time": [
0
],
"csg_proc_time": [
71
],
"perftech_proc_time": [
0
],
"csg_proc_end_time": [
"2018-06-17T04:15:57.000Z"
],
"csg_proc_start_time": [
"2018-06-17T04:14:46.000Z"
]
},
这就是我为重现您的问题所做的工作,它工作正常:
PUT test/doc/1
{
"csg_proc_end_time": "2018-06-17T04:15:57.000Z",
"csg_proc_start_time": "2018-06-17T04:14:46.000Z"
}
现在计算脚本字段中的处理时间:
GET test/_search
{
"script_fields": {
"proc_time": {
"script": {
"source": "(doc.csg_proc_end_time.value.millis - doc.csg_proc_start_time.value.millis) / 1000"
}
}
}
}
结果:71 秒
{
"_index": "test",
"_type": "doc",
"_id": "1",
"_score": 1,
"fields": {
"proc_time": [
71
]
}
}