Modify the content of a field using logstash

◇◆丶佛笑我妖孽 提交于 2020-01-07 03:13:09

问题


I am using logstash to get data from a sql database. There is a field called "code" in which the content has this structure:

PO0000001209

ST0000000909

And what I would like to do is to remove the 6 zeros after the letters to get the following result:

PO1209

ST0909

I will put the result in another field called "code_short" and use it for my query in elasticsearch. I have configured the input and the output in logstash but I am not sure how to do it using grok or maybe mutate filter

I have read some examples but I am quite new on this and I am a bit stuck.

Any help would be appreciated. Thanks.


回答1:


You could use a mutate/gsub filter for this but that will replace the value of the code field:

filter {
  mutate {
    gsub => [
      "code", "000000", "",
    ]
  }
}

Another option is to use a grok filter like this:

filter {
  grok {
    match => { "code" => "(?<prefix>[a-zA-Z]+)000000%{INT:suffix}" }
    add_field => { "code_short" => "%{prefix}%{suffix}"}
  }
}


来源:https://stackoverflow.com/questions/41958787/modify-the-content-of-a-field-using-logstash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!