logstash过滤器将文本添加到输出

时间:2018-10-11 14:11:12

标签: json elasticsearch filter format logstash

我正在尝试将json输入包含在其他一些json中。 我无法掌握过滤器的工作原理,我需要为我的应用程序提供示例。

我的json输入:

{
  "documents": {
      "name": "projects",
      "fields": {
        "done": {
          "booleanValue": false
        },
        "title": {
          "stringValue": "testtest"
        }
      },
      "createTime": "2018-10-09T10:16:45.835536Z",
      "updateTime": "2018-10-09T10:17:37.550249Z"
    }
}

输出应为:

{
 "fields": {
  "test": {
   "stringValue": "{\"documents\": {\"name\": \"projects\",\"fields\": {\"done\": {\"booleanValue\": false},\"title\": {\"stringValue\": \"testtest\"}},\"createTime\": \"2018-10-09T10:16:45.835536Z\",\"updateTime\": \"2018-10-09T10:17:37.550249Z\"}}"
  }
 }
}

2 个答案:

答案 0 :(得分:0)

假设您输入的内容如您所展示的那样,最肮脏的解决方案就是修改JSON。

#!/bin/bash
echo -e "{\"fields\":{\"test\":{\"stringValue\":\"" >> newjson.json
cat yourjson.json >> newjson.json
echo -e "\"}}}" >> newjson.json

答案 1 :(得分:0)

解决方案:

filter {
  mutate {
        rename => ["\"", "\\""]
  }
  mutate {
        rename => { "message" => "[stringValue]" }
  }
  mutate {
        rename => { "stringValue" => "[test][stringValue]"}
  }
  mutate {
        rename => { "test" => "[fields][test]"}
  }
  mutate {
    remove_field => ["@timestamp", "@version"]
  }
}