# Define filter - to use second field as timestamp and add year

**URL:** <https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684>\
**Category:** Logstash\
**Created:** [December 12, 2016, 9:31am UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684 "2016-12-12T09:31:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [December 12, 2016, 9:31am UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/1 "2016-12-12T09:31:57Z")

</div>

My logs entries look like that:

```
<<DEBUG>> **[Mar 01 14:55:18]** [[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] [CM] [OMS] (BasicParameter.getEffectiveDate) Exit
<<DEBUG>> [Mar 01 14:55:18] [[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] [CM] [OMS] (BasicParameter.getExpirationDate) Enter

```

I need to use the date as timestamp.

Following the code from my logstash.conf file:

```
            multiline {
                       patterns_dir => "/users/mpswrk1/LogStash/impls/patterns/patterns"
                       pattern => "^\<\<%{LOGLEVEL}\>\> "
                       negate => true
                       what => "previous"
            }
            grok {
                  match => { "message" => "\<\<%{LOGLEVEL:severity}\>\> \[%{PARTTIMESTAMP:timestamp}\] \[\[%{DATA:status}\] %{DATA:execute_thread}\] \[%{WORD:source_app}\] \(%{JAVACLASS:method}\) %{DATA:exception_method_description}\: \(%{DATA:error_code}\) %{DATA:error_description}%{JAVASTACKTRACEPART:java_class_stack}" }
                  patterns_dir => "/users/mpswrk1/LogStash/impls/patterns/patterns"
            }
            date {
                  match => ["timestamp" , "MMM dd, yyyy hh:mm:ss aa"]
            }

```

\*parttimestamp is a private  
`PARTTIMESTAMP %{MONTH} %{MONTHDAY} %{TIME`

Regards  
Sharon.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 12, 2016, 9:58am UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/2 "2016-12-12T09:58:42Z")

</div>

What's the question, exactly? Logstash will guess which year a log is from so you might not have to do anything.

---

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [December 12, 2016, 11:52am UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/3 "2016-12-12T11:52:41Z")

</div>

It doesn't work. I am getting in the timestamp the current date, of inserting into the elasticsearch.

Maybe the date { match {......} } line is wrong?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 12, 2016, 12:28pm UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/4 "2016-12-12T12:28:56Z")

</div>

Yes, you have to remove "yyyy" since there's no year in your timestamp. If the date filter fails it'll log an error message that usually points to where the problem is.

---

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [December 12, 2016, 1:14pm UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/5 "2016-12-12T13:14:42Z")

</div>

Will check and update. Thanks!

---

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [December 26, 2016, 12:55pm UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/6 "2016-12-26T12:55:27Z")

</div>

still not working, and I don't understand the reason.

This is how I defined it in the conf file:

```
            grok {
                  match => { "message" => "\<\<%{LOGLEVEL:severity}\>\> \[%{PARTTIMESTAMP:timestamp}\] \[\[%{DATA}\] %{DATA}\] \[%{DATA:application}\] \[%{DATA}\] \(%{JAVACLASS}\) %{CISCO_REASON}.%{JAVACLASS}: \(%{DATA:error_code}\)" }
                  patterns_dir => "/etc/logstash/patterns"
            }
            date {
                  match => ["timestamp" , "MMM dd HH:mm:ss"]
                  #add_field => { "Status" => "Matched"}
                  #remove_field => ["timestamp"]
            }
```

---

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [December 26, 2016, 2:28pm UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/7 "2016-12-26T14:28:19Z")

</div>

Working

---

<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 23, 2017, 2:28pm UTC](https://discuss.elastic.co/t/define-filter-to-use-second-field-as-timestamp-and-add-year/68684/8 "2017-01-23T14:28:45Z")

</div>

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