使用logstash修改字段的内容 [英] Modify the content of a field using logstash

查看:886
本文介绍了使用logstash修改字段的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用logstash从sql数据库获取数据。有一个称为代码的字段,其中的内容有
这个结构:

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

PO0000001209

ST0000000909

ST0000000909

我想做的是在字母后删除6个零,以获得以下结果:

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

PO1209

ST0909

我将结果放在另一个名为code_short的字段中,并使用它在我的查询在弹性搜索。我已经在logstash中配置了输入
和输出,但我不知道如何使用grok或者mutate过滤器来执行此操作。

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.

推荐答案

您可以使用 mutate / gsub 过滤器但是这将取代代码字段的值:

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

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

另一个选择是使用这样的 grok 过滤器:

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}"}
  }
}

这篇关于使用logstash修改字段的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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