# Replace timestamp with actual time from the log

**URL:** <https://discuss.elastic.co/t/replace-timestamp-with-actual-time-from-the-log/164813>\
**Category:** Logstash\
**Created:** [January 18, 2019, 2:52pm UTC](https://discuss.elastic.co/t/replace-timestamp-with-actual-time-from-the-log/164813 "2019-01-18T14:52:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arvind297](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@arvind297](https://discuss.elastic.co/u/arvind297)\
**Post date:** [January 18, 2019, 2:52pm UTC](https://discuss.elastic.co/t/replace-timestamp-with-actual-time-from-the-log/164813/1 "2019-01-18T14:52:59Z")

</div>

Hi,  
We are ingesting the log which is in the below format.

2019-01-17T19:01:48.440361Z D [2027:rrc\_poll] {t: 3e3dc5ce-0569-11e9-b17d-06a912e3abd4} connection -- update 1 of 1 existing devices, offset 0  
2019-01-17T19:01:48.559861Z I [2027:rrc\_poll] {t: 3e3dc5ce-0569-11e9-b17d-06a912e3abd4} client -- response -- Status 200

Below filter is being used

filter {  
if "yellow" in [tags] {  
grok {  
match =\> ["message", "%{DATA:status}: %{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:monthday}T%{TIME:time}Z: %{GREEDYDATA:detailed-message}"]  
}  
mutate {

# gsub =\> ["time","\d\d\d$",""]

```
                   add_field => {
                           "timestamp" => "%{year}-%{month}-%{monthday}T%{time}Z"
                   }
           }
           date {
                   match => ["timestamp", "yy-MM-dd:HH:mm:ss,SSSZ", "ISO8601"]
                   target => "@timestamp"
           }
           mutate {
                   remove_field => ["month", "monthday", "year", "time", "detailed-message"]
           }
   }

```

}

We need to change the timestamp with actual time the logs got generated.  
Can anyone please suggest me on the changes to be done in the filter.

---

<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:** [January 18, 2019, 3:15pm UTC](https://discuss.elastic.co/t/replace-timestamp-with-actual-time-from-the-log/164813/2 "2019-01-18T15:15:29Z")

</div>

You are making this far too complicated.

```
grok { "match" => { "message" => ["^%{NOTSPACE:ts}"] } }
date { match => ["ts", "ISO8601"] }

```

Done.

```
"@timestamp" => 2019-01-17T19:01:48.440Z,
```

---

<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:** [February 15, 2019, 3:15pm UTC](https://discuss.elastic.co/t/replace-timestamp-with-actual-time-from-the-log/164813/3 "2019-02-15T15:15:35Z")

</div>

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