# Simple Grok and Date filter problem

**URL:** <https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867>\
**Category:** Logstash\
**Created:** [February 18, 2019, 3:57pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867 "2019-02-18T15:57:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim3](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@Tim3](https://discuss.elastic.co/u/Tim3)\
**Post date:** [February 18, 2019, 3:57pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/1 "2019-02-18T15:57:12Z")

</div>

Hello, I recently tried to use ElasticSearch and Logstash, and I'm currently trying to get few fields from this log line :

2018-12-05 00:13:45,000 LogType - MachineNumber Message

I use this filter :

filter {  
grok {  
match =\> { "message" =\> "%{DATESTAMP:LogDate} %{WORD:LogType} - %{WORD:MachineNumber} %{GREEDYDATA:Message}" }  
}  
date {  
match =\> ["LogDate" , "yyyy-MM-dd HH:mm:ss,SSS"]  
target =\> "LogDate"  
}  
}

I'm able to get every fields that I want, but I want the date to be stored **as a Date** in LogDate. But in Kibana I have a logDate as a string (I guess it failed to convert to Date). And it's transformed as "0018-12-05T00:13:45,000Z".

Do you see anything wrong with my filter ? I must have misunderstood something in the Date thing. It may be a problem with the date format as well, but it seems OK.

---

<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:** [February 18, 2019, 4:08pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/2 "2019-02-18T16:08:39Z")

</div>

It could be that you have already ingested LogDate as a string in the current index. Can you start over with a new index? That filter looks fine.

---

<div class="post-metadata">

**Author:** ![Tim3](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@Tim3](https://discuss.elastic.co/u/Tim3)\
**Post date:** [February 18, 2019, 4:20pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/3 "2019-02-18T16:20:51Z")

</div>

Thank you @Badger , now my LogDate is now a date !  
I still have a problem : this field is filled with 0018-12-12, from the original 2018-12-12. Do you know how my Grok filter can skip the really first character ?

---

<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:** [February 18, 2019, 4:55pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/4 "2019-02-18T16:55:32Z")

</div>

> [@Tim3](#):
>
> grok {  
> match =\> { "message" =\> "%{DATESTAMP:LogDate} %{WORD:LogType} - %{WORD:MachineNumber} %{GREEDYDATA:Message}" }  
> }

DATESTAMP matches a two digit year. If you try to anchor that pattern to beginning of line

```
"^%{DATESTAMP:LogDate} %{WORD:LogType} - %{WORD:MachineNumber} %{GREEDYDATA:Message}"

```

then you get a \_grokparsefailure. I would use dissect instead of grok.

```
dissect { mapping => { "message" => "%{LogDate} %{+LogDate} %{LogType} - %{MachineNumber} %{Message}" } }

```

---

<div class="post-metadata">

**Author:** ![Tim3](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@Tim3](https://discuss.elastic.co/u/Tim3)\
**Post date:** [February 18, 2019, 5:03pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/5 "2019-02-18T17:03:46Z")

</div>

Ok, I tried your dissect and it works perfectly !  
Thank you so much !

---

<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:** [March 18, 2019, 5:03pm UTC](https://discuss.elastic.co/t/simple-grok-and-date-filter-problem/168867/6 "2019-03-18T17:03:57Z")

</div>

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