# Csv filter match date field

**URL:** <https://discuss.elastic.co/t/csv-filter-match-date-field/220428>\
**Category:** Logstash\
**Created:** [February 21, 2020, 5:42pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428 "2020-02-21T17:42:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.derosa](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@david.derosa](https://discuss.elastic.co/u/david.derosa)\
**Post date:** [February 21, 2020, 5:42pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/1 "2020-02-21T17:42:23Z")

</div>

I am trying to parse e csv. All works fine except for date field.

This is the format: _2020-02-21 18:25:37.254774_  
and this is my date code:

> ```
> date {
> match => ["date", "yyyy-MM-dd HH:mm:ss.SSS"]
> target => "@timestamp"
> }
> 
> ```

This is full csv line:  
`csvlog "2020-02-21 18:25:37.254774" srv1 10.10.100.1 48619 192.168.25.50 57027 TCP`

This is full logstash conf:

```
input {
            file {
             path => "/var/log/csv.log"
             start_position => "beginning"
           }
         }  
           filter {
                csv {
                    columns => [
                      "event.module",	
                      "date",		
                      "agent.hostname",	
                      "source.ip",		
                      "source.port",	
                      "destination.ip",	
                      "destination.port",	
                      "network.transport"
                    ]
            	add_tag => ["%{event.module}"]
            	add_field => {
            		"destination.address" => "%{destination.ip}"
            		"source.address" => "%{source.ip}"
            	}
                    separator => " "
                    remove_field => ["message"]
                }
                date {
                    match => ["date", "yyyy-MM-dd HH:mm:ss.SSS"]
                    target => "@timestamp"
                }
     }

```

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [February 21, 2020, 6:20pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/2 "2020-02-21T18:20:03Z")

</div>

remove target =\> "@timestamp" and it should work.

I did quick test and it did work

```
# cat stdin_test.conf
input { stdin { } }

filter {
   date { match => ["message", "dd/MMM/yyyy:HH:mm:ss"] }
}
output { stdout { codec => rubydebug } }

```

echo '21/Feb/2020:11:15:02' | /usr/share/logstash/bin/logstash -f stdin\_test.conf

and I got

```
{
         "@version" => "1",
       "message" => "21/Feb/2020:11:15:02", ---> original time
    "@timestamp" => 2020-02-21T17:15:02.000Z --> time in UTC
}
```

---

<div class="post-metadata">

**Author:** ![david.derosa](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@david.derosa](https://discuss.elastic.co/u/david.derosa)\
**Post date:** [February 21, 2020, 7:13pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/3 "2020-02-21T19:13:01Z")

</div>

Thank You for the answer.  
I found the problem but note the solution.

My date formate use a fraction of a second to long:  
2020-02-21 18:25:37. **254774** NOT WORK  
2020-02-21 18:25:37. **254** WORK

How can i truncate the date so the fraction of a second is smaller?

---

<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 21, 2020, 10:11pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/4 "2020-02-21T22:11:06Z")

</div>

Why not use a matching pattern?...

```
match => ["date", "yyyy-MM-dd HH:mm:ss.SSSSSS"]
```

---

<div class="post-metadata">

**Author:** ![david.derosa](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@david.derosa](https://discuss.elastic.co/u/david.derosa)\
**Post date:** [February 21, 2020, 11:04pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/5 "2020-02-21T23:04:05Z")

</div>

It works with yyyy-MM-dd HH:mm:ss.SSSSSS.

Thank you

---

<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 20, 2020, 11:04pm UTC](https://discuss.elastic.co/t/csv-filter-match-date-field/220428/6 "2020-03-20T23:04:06Z")

</div>

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