# Ruby Filter Exception

**URL:** <https://discuss.elastic.co/t/ruby-filter-exception/165190>\
**Category:** Logstash\
**Created:** [January 22, 2019, 8:45am UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190 "2019-01-22T08:45:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fadihaddad](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@fadihaddad](https://discuss.elastic.co/u/fadihaddad)\
**Post date:** [January 22, 2019, 8:45am UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/1 "2019-01-22T08:45:13Z")

</div>

hello, I am using this ruby filter to transform and map my data into a new field  
Dalist : "8~103511~0~103511~20181209|23~2660000~2382761~277239~20181209"  
transforming it to DAList =\> [  
[0] {  
"DA\_ID" =\> "8",  
"DA\_Before" =\> "275273",  
"DA\_Change" =\> "1687",  
"DA\_After" =\> "273586",  
"DA\_ExpDate" =\> "20181209"  
},  
[1] {  
"DA\_ID" =\> "23",  
"DA\_Before" =\> "2660000",  
"DA\_Change" =\> "0",  
"DA\_After" =\> "2660000",  
"DA\_ExpDate" =\> "20181209"  
}  
],  
I used this ruby filter code to also map the nested fields`  
ruby {  
code =\> "  
x = event.get('dAList').split('|').collect { |t|  
c = t.split '~'  
{  
'DA\_ID' =\> c[0].to\_i,  
'DA\_Before' =\> c[1].to\_i,-  
'DA\_After' =\> c[2].to\_i,  
'DA\_Change' =\> c[3].to\_i,  
'DA\_ExpDate' =\> Time.strptime(c[4], '%Y%m%d')  
}  
}  
event.set('DAList', x)

"  
}  
`

my first problem is that some documents are being throwed because they are not parsing the date Format of DA\_ExpDate giving this error \\01/25/19\\ is malformed at \"/25/19\""  
and how can I set the time zone the the DA\_ExpDate

---

<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 22, 2019, 2:26pm UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/2 "2019-01-22T14:26:12Z")

</div>

If there are multiple formats you might be better off with a date filter. That also handle timezones.

```
date {
    match => ["[DAList][0][DA_ExpDate]", "YYYYMMdd", "MM/dd/YY" ]
    target => "[DAList][0][DA_ExpDate]"
    timezone => "Asia/Qyzylorda"
}
date {
    match => ["[DAList][1][DA_ExpDate]", "YYYYMMdd", "MM/dd/YY" ]
    target => "[DAList][1][DA_ExpDate]"
    timezone => "Asia/Qyzylorda"
}
```

---

<div class="post-metadata">

**Author:** ![fadihaddad](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@fadihaddad](https://discuss.elastic.co/u/fadihaddad)\
**Post date:** [January 22, 2019, 2:54pm UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/3 "2019-01-22T14:54:47Z")

</div>

can I use 1 date filter for dynamic instead of [0],[1],[2],[3]…..etc

---

<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 22, 2019, 3:06pm UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/4 "2019-01-22T15:06:51Z")

</div>

No. Unfortunately the date filter does not accept an array of strings as an input (and return an array of timestamps). You either have multiple date filters, or start implementing a significantly more complex ruby filter that tests against multiple date formats and handles timezones.

---

<div class="post-metadata">

**Author:** ![fadihaddad](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@fadihaddad](https://discuss.elastic.co/u/fadihaddad)\
**Post date:** [January 22, 2019, 3:08pm UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/5 "2019-01-22T15:08:26Z")

</div>

okay thank you so much for your help

---

<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 19, 2019, 3:08pm UTC](https://discuss.elastic.co/t/ruby-filter-exception/165190/6 "2019-02-19T15:08:30Z")

</div>

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