1

我有一个场景,我有两种非常相似的输入格式,但我需要一个 Jolt 规范来一致地处理这两种格式。

这是输入样式 1

{
    "creationTime": 1503999158000,
    "device": {
        "ip": "155.157.36.226",
        "hostname": "server-123.example.int"
    }
}

这是输入样式 2

{
    "creationTime": 1503999158000,
    "device": {
        "ip6": "2001::face",
        "hostname": "server-123.example.int"
    }
}

唯一的区别是样式 1使用device.ip样式 2使用device.ip6。这些字段中的任何一个或都不会存在,但绝不会同时存在。

我想简单地提取以下内容:

{
    "created_ts": 1503999158000,
    "src_ip_addr": "....."
}

我需要设置为和src_ip_addr中存在的任何字段。如果源数据中不存在任何字段,则该值应默认为。ipip6null

这可以通过一个单一的 Jolt 规格实现吗?

4

2 回答 2

3

具有两个操作的单个规范。

规格

[
  {
    "operation": "shift",
    "spec": {
      "creationTime": "created_ts",
      "device": {
        // map ip or ip6 to src_ip_addr
        "ip|ip6": "src_ip_addr"
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      // if src_ip_addr does not exist, then apply a default of null
      "src_ip_addr": null
    }
  }
]
于 2018-01-19T17:23:44.560 回答
0

我尝试了以下方法,它符合我的要求:

[
  {
    "operation": "shift",
    "spec": {
      "creationTime": "created_ts",
      "device": {
        // map both to src_ip_addr, whichever one is present will be used
        "ip": "src_ip_addr",
        "ip6": "src_ip_addr"
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "src_ip_addr": null
    }
  }
]
于 2018-01-20T13:39:45.243 回答