1

我知道有人问过这个问题,但 ELK 似乎变化非常迅速,也许在这一点上有些事情是可能的。所以,我使用的是 Kibana 4,我试图可视化(或至少计算)查询中两个文档之间的时间差。我的文档是批处理过程中的日志,其中包含很多字段,时间戳就是其中之一(“日期”类型)。是否可以使用脚本字段计算查询中连续文档之间的时间差?(返回什么类型并不重要)。

我希望我是有道理的,我是 ELK 的新手。提前致谢。

道塔

4

1 回答 1

0

_据我了解,您不能在 Kibana 中这样做,因为脚本字段一一应用于文档。但是,如果对您来说重要的是获得计算结果,您可以使用 ES 查询中的 scripted_metric 聚合来完成此操作。

我认为它可能看起来像

{
    "sort" : [
        { "mydatefield" : {"order" : "asc"}}
    ],
    "query" : {
        (something of match, range, match_all...)
    },
    "aggregations": {
        "scripted_metric": {
            "init_script": "(declarations, eg :) _agg['myarray']=[]",
            "map_script": (store relevant timestamps in datastructure, eg :) "_ạgg.myarray.add(doc['mydatefield'])",
            "reduce_script": "(aggregate results, eg :) otherarray = [] ; for (x in ạggs){otherarray.putAll(x.myarray)} ;
            (and sort otherarray) ; result = [] ;
           for (i = 0 ; i < otherarray.length-1 ; i++){result.add(otherarray[i+1]-otherarray[i])} ;
           return result ;"
        }
    }
}
于 2015-06-26T14:02:11.970 回答