我有一个名为"Priority“的字段,它有像1到10这样的整数值,这里1是最低值,10是最高值。如何显示字符串值,而不是数字,以使此字段更容易理解。因此新字段应包含3个值,即
low ---> if priority lies in 1 to 3
Medium---> if priority lies in 4-7
high---->if priority lies in 8-10
发布于 2015-10-28 17:13:34
首先,您需要确保您的优先级值是int
类型。在此之后,您可以使用logstash's conditionals将值更改为字符串。
示例配置:
input { stdin {} }
filter {
grok { match => { "message" => [" %{NUMBER:priority:int}" ] } }
if [priority] < 4 {
mutate { replace => { "priority" => "low" } }
} else if [priority] < 8 {
mutate { replace => { "priority" => "medium" } }
} else {
mutate { replace => { "priority" => "high" } }
}
}
output {stdout { codec => rubydebug }}
请注意,grok filter会将您的数字解析为int
类型的字段。
%{NUMBER:priority:int}
这意味着,无论您从何处获取优先级字段,都需要注意它包含一个int。否则,您可以通过比较字符串值来执行此操作。
发布于 2015-10-29 01:00:48
我建议您保留两个字段:数字和字符串(漂亮)版本。这样,您就可以根据数字运行有效的查询,并在图表上显示字符串,等等。
更多信息here。
https://stackoverflow.com/questions/33384602
复制相似问题