Regex field starts with a string

I want to add a new field if a field start with a certain string. Added below code in filter { }, to set a new field error as "Y" if text starts with ERROR: . Doesnt seem to work.

  if "[dest][text]" =~ /^ERROR: .*/ {
     mutate { add_field => { "error" => "Y" } }
  }

Can you try the following

     if [dest][text] =~ "ERROR:" {
     mutate { add_field => { "error" => "Y" } }
  }
1 Like

This I have tried already but the above code will check for ERROR: any where in the text field and not specifically starting with ERROR:

Small syntax change that worked: (to check for ERROR: anywhere in the text)

  if ([dest][text] =~ "ERROR:") {
     mutate { add_field => { "error" => "ERROR" } }

The above syntax change in my previous code worked to see if text begins with ERROR:

if ([dest][text] =~ /^ERROR:.*/ ) {
      mutate { add_field => { "error" => "Y" } }
}
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.