【问题标题】:Logstash JSON Parse - Ignore or Remove Sub-TreeLogstash JSON Parse - 忽略或删除子树
【发布时间】:2015-06-13 00:15:24
【问题描述】:

我使用如下配置将 JSON 发送到 logstash:

filter {
    json {
      source => "event"
      remove_field => [ "event" ]
    }
  }

这是我发送的 JSON 对象示例:

   {
      "@timestamp": "2015-04-07T22:26:37.786Z",
      "type": "event",
      "event": {
        "activityRecord": {
          "id": 68479,
          "completeTime": 1428445597542,
          "data": {
            "2015-03-16": true,
            "2015-03-17": true,
            "2015-03-18": true,
            "2015-03-19": true
          }
        }
      }
    }

由于activityRecord.data 对象的任意性质,我不希望logstash 和elasticsearch 索引所有这些日期字段。照原样,我将activityRecord.data.2015-03-16 视为在 Kibana 中过滤的字段。

有没有办法忽略这个数据子树?或者至少在它已经被解析后删除它?我尝试使用通配符之类的 remove_field,但没有运气。

【问题讨论】:

    标签: json filter logstash kibana


    【解决方案1】:

    虽然不完全直观,但 documented 子字段引用是用方括号进行的,例如[field][subfield],这就是你必须使用 remove_field 的内容:

    mutate {
      remove_field => "[event][activityRecord][data]"
    }
    

    要使用通配符匹配删除字段,您必须使用 ruby filter

    【讨论】:

    • 谢谢,红宝石块适用于:if [event] and [event][activityRecord] { ruby { code => "event['event']['activityRecord']['data'] = {}" } }
    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多