# Copy \`@timestamp\` in Logstash

**URL:** https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430
**Category:** Logstash
**Created:** [July 10, 2018, 9:14pm UTC](https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430 "2018-07-10T21:14:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![amomchilov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amomchilov/32/30271_2.png) [@amomchilov](https://discuss.elastic.co/u/amomchilov)
#### Post date: [July 10, 2018, 9:14pm UTC](https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430/1 "2018-07-10T21:14:22Z")

</div>

I would like to preserve the `@timestamp` field prior to overwriting it from a `date` filter, so that I can know when a document was processed by logstash.

I also tried using the `copy` filter, but that fails silently.

```
  mutate {
      copy => { "%{@timestamp}" => "logstash_intake_timestamp" }
  }

```

I tried this, but it also caused exceptions (I don't have the stack trace right now, but I could get it if it would help the investigation).

```
  mutate {
      copy => { "@timestamp" => "logstash_intake_timestamp" }
  }

```

I tried using the `event` API, but it leads to [this exception](https://pastebin.com/ufdh2tx2).

```
ruby {
    code => "event.set('read_time', event.get('@timestamp'))"
}

```

What's the correct way to copy `@timestamp`?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 11, 2018, 6:09am UTC](https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430/2 "2018-07-11T06:09:36Z")

</div>

Might something like this work?

```auto
mutate {
  add_field => { "logstash_intake_timestamp"=> "%{@timestamp}" }
}

```

---

<div class="post-metadata">

### Author: ![amomchilov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amomchilov/32/30271_2.png) [@amomchilov](https://discuss.elastic.co/u/amomchilov)
#### Post date: [July 11, 2018, 6:25am UTC](https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430/3 "2018-07-11T06:25:20Z")

</div>

Oh boy, I didn't RTFM:

> [@copy (emphasis mine)](#):
>
> Copy an existing field _ **to another field** _. Existing target field will be overriden.

> [@add\_field (emphasis mine)](#):
>
> If this filter is successful, add any arbitrary fields to this event. Field names can be dynamic and include parts of the event using the %{field}.

I'll try this tomorrow and report back!

---

<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: [August 8, 2018, 6:25am UTC](https://discuss.elastic.co/t/copy-timestamp-in-logstash/139430/4 "2018-08-08T06:25:28Z")

</div>

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