有什么办法可以将Logstash中的JSON数据展平 [英] Is there any way to flatten json data in logstash

查看:65
本文介绍了有什么办法可以将Logstash中的JSON数据展平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSON

{
 "foo1":{
  "number":1,
  "type":"In progrss",
  "submit_time":"2020-10-04",
  "id_type":"2153707",
  "order_id":"1601849877",
  "foo2":[
     {
        "t1":"xyz",
        "t2":"qwe",
        "t3":"yty"
     }
  ],
  "order_date":"19/09/2020",
  "shipping_date":"2020-10-04",
  "shipping_id":"89775555",
  "tracking_id":"98876"
 }
}

我想要这样:

 "number": 1,
 "type": "in progrss",
 "submit_time": "2020-10-04T16:17:33-0600",
 "id_type": 2153707,
 "order_id": 1601849877,
 "order_date": 19/09/2020,
 "shipping_date": "2020-10-04T16:17:57-0600",
 "shipping_id": "89775555",
 "tracking_id": "98876",
 "order_id": 1601849877,
  "foo2": [
    "xyz",
    "we",
    "yty"
      ],

我尝试了 filter {json {source =>foo1"目标=>" jsoncontent"}} 但是它什么也没给我.我在过滤器部分中缺少的任何东西,或者有其他任何方法可以使用.谢谢您提前

I tried filter { json { source => "foo1" target => "jsoncontent" } } But its not giving me anything . Anyything that i am missing in the filter part or is there any different way to do .Thanks in Advance

推荐答案

如果对JSON进行了扁平化处理,请检查

If you are after flattening of the JSON check this answer on Elastic Discuss. The ruby script solution in that discussion thread will give below output.

{
         "foo1.order_id" => "1601849877",
             "foo1.foo2" => [
        [0] {
            "t1" => "xyz",
            "t3" => "yty",
            "t2" => "qwe"
        }
    ],
       "foo1.order_date" => "19/09/2020",
          "foo1.id_type" => "2153707",
                  "host" => "37eda5039626",
            "@timestamp" => 2020-10-06T08:30:22.463Z,
                  "type" => "json",
      "foo1.submit_time" => "2020-10-04",
             "foo1.type" => "In progrss",
                  "path" => "/usr/share/logstash/stack/data/file.json",
           "foo1.number" => 1,
    "foo1.shipping_date" => "2020-10-04",
      "foo1.tracking_id" => "98876",
              "@version" => "1",
      "foo1.shipping_id" => "89775555"
}

这篇关于有什么办法可以将Logstash中的JSON数据展平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆