Kibana 使用聚合或分组两个数据集制作甘特

5vf7fwbs  于 2023-05-12  发布在  Kibana
关注(0)|答案(1)|浏览(275)

我正在制作一个甘特来显示一些正在进行的和重叠的任务,我的问题数据与此类似,

{
{hashcode=idR, operation='start', time=09-May-2023 14:08:17.900,userName='B',OperationName='abc.c'}
{hashcode=id1, operation='start', time=09-May-2023 14:08:17.925,userName='A',OperationName='abc.c'}
{hashcode=id2, operation='start', time=09-May-2023 14:08:17.927,userName='A',OperationName='def.c'}
{hashcode=id2, operation='end', time=09-May-2023 14:08:17.970,userName='A',OperationName='def.c'}
{hashcode=id1, operation='end', time=09-May-2023 14:08:17.986,userName='A',OperationName='def.c'}
}

我的想法是根据他们拥有的公共散列代码从每个记录中找到开始和结束日期/时间。在X轴上,我想把时间标度和Y轴的hashcode或用户名。
虽然我尝试了一些甘特图表,但我没有得到任何成功,因为我不能俱乐部两个不同的设置在一个得到开始和结束日期在一个记录本身。
你可以请提供一些想法,我如何才能实现我的目标,最少的负载(更快)在Kibana服务器?我们有v7.17.7版本设置。
我做了下面的甘特图,在同一个记录中,我有开始和结束日期

但是我不确定我应该用什么聚合来俱乐部两个记录。

1zmg4dgp

1zmg4dgp1#

有几种方法可以合并数据集,但一种简单的方法是简单地应用一些转换聚合(min,max等)并在“hashcode”列上分组。

"transform": [
    {
      "aggregate": [
        {"op": "min", "field": "time", "as": "start"},
        {"op": "max", "field": "time", "as": "end"},
        {"op": "max", "field": "userName", "as": "userName"},
        {"op": "max", "field": "OperationName", "as": "OperationName"}
      ],
      "groupby": ["hashcode"]
    }
  ],

完整规格:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "A simple Gantt chart",
  "data": {
    "values": [
      {
        "hashcode": "idR",
        "operation": "start",
        "time": "2023-04-01T14:08:17.900Z",
        "userName": "B",
        "OperationName": "abc.c"
      },
      {
        "hashcode": "id1",
        "operation": "start",
        "time": "2023-04-01T14:08:17.925Z",
        "userName": "A",
        "OperationName": "abc.c"
      },
      {
        "hashcode": "id2",
        "operation": "start",
        "time": "2023-05-03T14:08:17.927Z",
        "userName": "A",
        "OperationName": "def.c"
      },
      {
        "hashcode": "id2",
        "operation": "end",
        "time": "2023-05-09T14:08:17.970Z",
        "userName": "A",
        "OperationName": "def.c"
      },
      {
        "hashcode": "id1",
        "operation": "end",
        "time": "2023-05-09T14:08:17.986Z",
        "userName": "A",
        "OperationName": "def.c"
      }
    ]
  },
  "transform": [
    {
      "aggregate": [
        {"op": "min", "field": "time", "as": "start"},
        {"op": "max", "field": "time", "as": "end"},
        {"op": "max", "field": "userName", "as": "userName"},
        {"op": "max", "field": "OperationName", "as": "OperationName"}
      ],
      "groupby": ["hashcode"]
    }
  ],
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "hashcode",
      "type": "nominal",
      "axis": {"title": "Hashcode"}
    },
    "x": {
      "field": "start",
      "type": "temporal",
      "axis": {"title": "Start Time", "format": "%Y-%m-%d", "grid": false}
    },
    "x2": {"field": "end"},
    "color": {
      "field": "userName",
      "type": "nominal",
      "legend": {"title": "User Name"}
    },
    "tooltip": [
      {"field": "OperationName", "type": "nominal", "title": "Operation Name"},
      {"field": "userName", "type": "nominal", "title": "User Name"},
      {"field": "start", "type": "temporal", "title": "Start Time"},
      {"field": "end", "type": "temporal", "title": "End Time"}
    ]
  },
  "config": {}
}

相关问题