# Extract date and time from message field into a dedicated field

**URL:** <https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908>\
**Category:** Logstash\
**Created:** [September 18, 2019, 5:30am UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908 "2019-09-18T05:30:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vipin\_Gaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vipin_gaur/32/46948_2.png) [@Vipin\_Gaur](https://discuss.elastic.co/u/Vipin_Gaur)\
**Post date:** [September 18, 2019, 5:30am UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908/1 "2019-09-18T05:30:59Z")

</div>

how to extract date and time from message field into a dedicated field.  
this is my .conf file

input {  
beats {  
port =\> 5044

```auto
    }

```

}  
filter {  
if [log\_type] == "json" {  
mutate {  
rename =\> {  
"message" =\> "raw\_data"  
}  
}  
json {  
source =\> "raw\_data"  
}  
date {  
match =\> ["timestamp", "ISO8601"]  
}  
}

```auto
    if [fields][log_type] == "nojson" {

         grok {
                  match => {"message" => ["(?m)%{LOGLEVEL:level}\s*\[%{TIMESTAMP_ISO8601:timestamp}\]\s*\[(?<thread>[\w._.-]+)\]\s*(?<logger>[\w\.\w]+)\s*(?<message>[^{]*)","(?m)%{LOGLEVEL:level}\s*\[%{TIMESTAMP_ISO8601:timestamp}\]\s*\[(?<thread>[\w\-\s./]+)\]\s*%{UUID:requestid}(?<message>[^{]*)"] }

                }
        }

  }

```

output {

# stdout { codec =\> rubydebug }

```auto
    elasticsearch {
            hosts => ["localhost:9160"]
            index => "logstash-api-logs-%{+YYYY-MM-dd}"
            manage_template => false}

```

#file { path =\> "/opt/elk\_data/devops/devops-%{+YYYY-MM-dd}.log" }  
}

---

<div class="post-metadata">

**Author:** ![pathri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pathri/32/54484_2.png) [@pathri](https://discuss.elastic.co/u/pathri)\
**Post date:** [September 18, 2019, 6:00am UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908/2 "2019-09-18T06:00:57Z")

</div>

please paste 1 sample entry of you data too

---

<div class="post-metadata">

**Author:** ![Vipin\_Gaur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vipin_gaur/32/46948_2.png) [@Vipin\_Gaur](https://discuss.elastic.co/u/Vipin_Gaur)\
**Post date:** [September 18, 2019, 12:44pm UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908/3 "2019-09-18T12:44:12Z")

</div>

DEBUG [2019-09-18 12:40:55,174] [dw-50 - POST /thirdparty/knowlarity/c2cCallInfo] 17975e1d-9e28-4ed2-a420-37e92f5662c8 i.e.a.a.BasicOAuthAuthenticator - {"message":"found user THIRDPARTYSUPPORT\_user/KNOWLARITY for credentials secret\_96c46e36-235b-4a0e-b977-3cbeb42c292c"}  
DEBUG [2019-09-18 12:40:55,174] [dw-50 - POST /thirdparty/knowlarity/c2cCallInfo] 17975e1d-9e28-4ed2-a420-37e92f5662c8 i.e.a.a.EPaylaterAuthorizer - {"message":"calling authorizer for user THIRDPARTYSUPPORT\_user/KNOWLARITY and role KNOWLARITY"}

---

<div class="post-metadata">

**Author:** ![Mahesh\_Guntumadugu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahesh_guntumadugu/32/54413_2.png) [@Mahesh\_Guntumadugu](https://discuss.elastic.co/u/Mahesh_Guntumadugu)\
**Post date:** [September 18, 2019, 4:51pm UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908/4 "2019-09-18T16:51:52Z")

</div>

You can try the following pattern for datetime field extraction

grok {  
match =\> { "datetimeinputfield" =\> "%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day} %{TIME:time}" }  
}  
mutate {  
add\_field =\> ["dedicated\_field","%{year}-%{month}-%{day} %{time}"]  
}

---

<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:** [October 16, 2019, 4:52pm UTC](https://discuss.elastic.co/t/extract-date-and-time-from-message-field-into-a-dedicated-field/199908/5 "2019-10-16T16:52:03Z")

</div>

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