# Logstash Filter Theory

**URL:** https://discuss.elastic.co/t/logstash-filter-theory/124883
**Category:** Logstash
**Created:** [March 21, 2018, 12:59am UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883 "2018-03-21T00:59:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wendt](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@wendt](https://discuss.elastic.co/u/wendt)
#### Post date: [March 21, 2018, 12:59am UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/1 "2018-03-21T00:59:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [March 21, 2018, 6:57pm UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/2 "2018-03-21T18:57:24Z")

</div>

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.

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

```

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

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

```

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [March 21, 2018, 8:17pm UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/3 "2018-03-21T20:17:36Z")

</div>

> 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:

> <https://github.com/logstash-plugins/logstash-filter-mutate/blob/v3.3.1/lib/logstash/filters/mutate.rb#L247-L265>

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

---

<div class="post-metadata">

### Author: ![wendt](https://avatars.discourse-cdn.com/v4/letter/w/4bbf92/32.png) [@wendt](https://discuss.elastic.co/u/wendt)
#### Post date: [March 21, 2018, 8:25pm UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/4 "2018-03-21T20:25:01Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [March 21, 2018, 8:26pm UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/5 "2018-03-21T20:26:05Z")

</div>

> 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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 18, 2018, 8:26pm UTC](https://discuss.elastic.co/t/logstash-filter-theory/124883/6 "2018-04-18T20:26:10Z")

</div>

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