Logstash Filter Theory

Do mutate functions build on each other? For example, if I were to rename a field and then wanted to send the text of that field to lower case, would I use the name of the original field, or the renamed version?

Ex. stacking functions
filter {
  mutate {
    rename => { "fruit" => "apple" }
    lowercase => [ "apple" ]
  }
}

Ex. non-stacking functions
filter {
  mutate {
    rename => { "fruit" => "apple" }
    lowercase => [ "fruit" ]
  }
}

Sorry for the formatting, still figuring out how to post here

The pipeline is read line by line, if you rename a field, everything else that you want to do with this field will need to use the new name.

This work without any problem.

filter {
  mutate {
    rename => { "fruit" => "apple" }
    lowercase => [ "apple" ]
  }
}

This does not work, since the field fruit does not exist anymore.

filter {
  mutate {
    rename => { "fruit" => "apple" }
    lowercase => [ "fruit" ]
  }
}

The pipeline is read line by line

FIlters are processed in the order listed, yes, but within a filter the order shouldn't be relied upon. This is especially true for the mutate filter where the different operations run in a fixed order:

If you have operations that need to run in a particular order (like in the examples above) you must use separate mutate filters.

2 Likes

Thank you for the explanation, that's extremely helpful!

Clarifying so I don't misrepresent this information in the future - the fixed order for mutate operations is as listed above (at least until the code is updated/changed), where coerce operations are run first, then rename operations, then update operations, and so on?

Clarifying so I don't misrepresent this information in the future - the fixed order for mutate operations is as listed above (at least until the code is updated/changed), where coerce operations are run first, then rename operations, then update operations, and so on?

That's correct.

1 Like

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