gpt4 book ai didi

elasticsearch - 无痛:获得时差

转载 作者:行者123 更新时间:2023-12-03 00:51:12 26 4
gpt4 key购买 nike

我对Painless非常陌生。我想编写一个简单的脚本来获取@timestamp和T1之间的时差(以毫秒为单位)。

我已经尝试使用doc ['somefield']。value和doc ['somefield']。date.millis,但是我可以访问 @timestamp ,但不能访问 T1

任何帮助将不胜感激!我在下面发布了示例数据源:

{
"_source": {
"@timestamp": "2018-11-06T00:20:08.802Z",
"fields": {
"T1": "2018-11-06T00:20:07.862Z",
}
}

最佳答案

您可以创建一个脚本字段,以返回@timestampfields.T1之间的差异,如下所示:

POST your-index/_search
{
"script_fields": {
"diff": {
"script": {
"source": """
def ts = Instant.parse(params._source['@timestamp']);
def t1 = Instant.parse(params._source.fields.T1);
return ChronoUnit.MICROS.between(ts, t1);

"""
}
}
}
}

关于elasticsearch - 无痛:获得时差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53178425/

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