Can anyone show me what an if
statement with a regex looks like in logstash?
My attempts:
if [fieldname] =~ /^[0-9]*$/
if [fieldname] =~ "^[0-9]*$"
Neither of which work.
What I intend to do is to check if the "fieldname" contains an integer
To combine the other answers into a cohesive answer.
Your first format looks correct, but your regex is not doing what you want.
/^[0-9]*$/
matches:^
: the beginning of the line[0-9]*
: any digit 0 or more times$
: the end of the lineSo your regex captures lines that are exclusively made up of digits. To match on the field simply containing one or more digits somewhere try using
/[0-9]+/
or/\d+/
which are equivalent and each match 1 or more digits regardless of the rest of the line.In total you should have:
You need this regex (and brackets, I think):
Your first format works (for me at the time of writing).
Check the current logstash version in the below excerpt, and also watch for the
uuid
field present in the output upon match. As expected, empty field matches too, but otherwise it is perfect.I suggest you to test stuff with such short stdin-stdout configurations. Logstash and Elastic stuff is great, but all too often the corner cases are not properly discussed in the documentation. They develop code faster than the docs as we are all tempted.
^
asserts position at start of the string$
asserts position at the end of the stringYour regexp just match the number string, and check contains an integer need remove
^
and$
.The simplest way is to check for
\d