# Move all @metadata fields at once

**URL:** <https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331>\
**Category:** Logstash\
**Created:** [April 4, 2019, 7:02am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331 "2019-04-04T07:02:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [April 4, 2019, 7:02am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331/1 "2019-04-04T07:02:06Z")

</div>

Hi,

is there a way to move all @metadata fields at once so i can preserve it over multiple logstash instances until it gets to ES?

Maybe something like a recursive

```
mutate { rename => { "@metadata" => "meta" } }

```

because when I do it this way, i only get `"meta" : null`

Thanks

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [April 4, 2019, 10:22am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331/2 "2019-04-04T10:22:32Z")

</div>

Are you certain `@metadata` exists?

With a bare-bones config there is no @metadata created.

```auto
input {
  generator { message => "a message" count => 1 }
}

# filter {
# mutate {
# copy => { "@metadata" => "metacopy" }
# rename => { "@metadata" => "meta" }
# }
# }

output {
  stdout { codec => rubydebug {metadata => true } }
}

```

Gives

```auto
{
      "sequence" => 0,
    "@timestamp" => 2019-04-04T10:02:43.286Z,
          "host" => "Elastics-MacBook-Pro.local",
      "@version" => "1",
       "message" => "a message"
}

```

Maybe `mutate/copy` is closer to your intended use case.

```auto
input {
  generator {
    message => "a message"
    count => 1
    add_field => {"[@metadata][foo]" => "bar"}
  }
}

filter {
  mutate {
     copy => { "@metadata" => "metacopy" }
  }
}

output {
  stdout { codec => rubydebug {metadata => true } }
}

```

Gives:

```auto
{
      "sequence" => 0,
    "@timestamp" => 2019-04-04T10:06:17.556Z,
     "@metadata" => {
        "foo" => "bar"
    },
      "metacopy" => {
        "foo" => "bar"
    },
      "@version" => "1",
          "host" => "Elastics-MacBook-Pro.local",
       "message" => "a message"
}

```

The rename (and copy) are "recursive" as rename one change the key name that is pointing to a hash of values and copy should create a new key with a clone of the value to be copied.

---

<div class="post-metadata">

**Author:** ![gruselglatz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gruselglatz/32/42675_2.png) [@gruselglatz](https://discuss.elastic.co/u/gruselglatz)\
**Post date:** [April 4, 2019, 10:26am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331/3 "2019-04-04T10:26:01Z")

</div>

Yes I did have @metadata fields from a filebeat, I also confirmed it with a debug output.

Currently I copy it field by field, i will try it later if its working with copy to move all @metadata fields at once.

Thanks so far

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 4, 2019, 11:42am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331/4 "2019-04-04T11:42:09Z")

</div>

You cannot rename [@metadata] due to [this](https://github.com/logstash-plugins/logstash-filter-mutate/issues/77) issue.

---

<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:** [May 2, 2019, 11:42am UTC](https://discuss.elastic.co/t/move-all-metadata-fields-at-once/175331/5 "2019-05-02T11:42:10Z")

</div>

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