# Add new field based on another field

**URL:** https://discuss.elastic.co/t/add-new-field-based-on-another-field/160064
**Category:** Logstash
**Created:** [December 9, 2018, 7:08pm UTC](https://discuss.elastic.co/t/add-new-field-based-on-another-field/160064 "2018-12-09T19:08:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan44785372](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan44785372/32/38610_2.png) [@Ivan44785372](https://discuss.elastic.co/u/Ivan44785372)
#### Post date: [December 9, 2018, 7:08pm UTC](https://discuss.elastic.co/t/add-new-field-based-on-another-field/160064/1 "2018-12-09T19:08:12Z")

</div>

Hello.  
I have such field in filebeat output docker.container.labels.app  
it looks like this:

```auto
    "docker" => {
        "container" => {
                "id" => "7549e137-3394-987d-f3cc-f79759851a62",
                "labels" => {
                    "app" => "app1",
                    "env" => "production",
        }
     }

```

I want to set another field in logstash based on this field - docker.container.labels.app  
I have such configuration:

```auto
filter {
        if ("" in [docker.container.labels.app]) {
            mutate {
                add_field => { "app" => "unknown" }
            }
        } else {
            mutate {
                add_field => { "app" => [docker.container.labels.app] }
            }
        }
}

```

But it doesn't work. Can you help me ?

---

<div class="post-metadata">

### Author: ![Ivan44785372](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan44785372/32/38610_2.png) [@Ivan44785372](https://discuss.elastic.co/u/Ivan44785372)
#### Post date: [December 9, 2018, 7:35pm UTC](https://discuss.elastic.co/t/add-new-field-based-on-another-field/160064/2 "2018-12-09T19:35:45Z")

</div>

Sorry. I found the solution.

add\_field =\> { "app" =\> "%{[docker][container][labels][app]}"

---

<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: [January 6, 2019, 7:35pm UTC](https://discuss.elastic.co/t/add-new-field-based-on-another-field/160064/3 "2019-01-06T19:35:54Z")

</div>

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