首页 > 解决方案 > Elasticsearch、Kibana、Vega Sankey - 自定义查询以仅针对 Top Talker IP 地址显示 Sankey

问题描述

我想在 Kibana 中创建 Sankey 图,仅用于网络流量上的顶级谈话者 IP 地址。Elasticsearch 有数千个关于连接的文档。文档包含源 IP、目标 IP 和字节数。目前我使用 Kibana 的 Vega 插件来显示所有连接(所有源 ips)的桑基图。 https://www.elastic.co/blog/sankey-visualization-with-vega-in-kibana

Vega 的 Elasticsearch 查询如下所示:

 {
  $schema: https://vega.github.io/schema/vega/v3.0.json
  title: Source/Destination Flows
  data: [
    {
      name: rawData
      url: {
        %context%: true
        %timefield%: ts
        index: graylog*
        body: {
          size: 0
          aggs: {
            table: {
              composite: {
                size: 30
                sources: [
                  {
                    stk1: {
                      terms: {field: "srcip"}
                    }
                  }
                  {
                    stk2: {
                      terms: {field: "dstip"}
                    }
                  }
                ]
              }
            }
          }
        }
      }
      format: {property: "aggregations.table.buckets"}
      transform: [
        {type: "formula", expr: "datum.key.stk1", as: "stk1"}
        {type: "formula", expr: "datum.key.stk2", as: "stk2"}
        {type: "formula", expr: "datum.doc_count", as: "size"}
      ]
    }
        ...

为了捕捉顶级谈话者 IP,我创建了这样的查询:

GET /graylog_0/_search
{
  "size": 0,
  "aggs": {
    "top_talker_by_traffic_value": {
      "terms": {
        "field": "srcip",
        "size": 1,
        "order": {
          "total_bytes": "desc"
        }
      },
      "aggs": {
        "total_bytes": {
          "sum": {
            "field": "byt"
          }
        }
      }
    }
  }
}

我的问题是,我可以使用该查询结果中的 IP 地址在 Vega 插件中进行另一个查询(类似于“WHERE srcip =“{IP Address from first query}”。如果是,我可以只通过一个查询来完成吗?

标签: elasticsearchkibanavega-litevegasankey-diagram

解决方案


推荐阅读