# Date parsing problem

**URL:** https://discuss.elastic.co/t/date-parsing-problem/128030
**Category:** Logstash
**Created:** [April 13, 2018, 11:04pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030 "2018-04-13T23:04:25Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 13, 2018, 11:04pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/1 "2018-04-13T23:04:25Z")

</div>

I don't know why, but the date filter is not parsing the date field and I don't see any error logs regarding it. The docs do have the `_dateparsefailure` tag though. My config:

```auto
  xml {
    source => "message"
    xpath => ["/element/date/text()", "date"]
    store_xml => false
  }
  date {
    match => ["date", "yyyyMMdd"]
    target => "date"
  }

```

The date fields are all like `20180425`. Any ideas why this is happened?

---

<div class="post-metadata">

### Author: ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)
#### Post date: [April 14, 2018, 1:37pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/2 "2018-04-14T13:37:45Z")

</div>

@arisbanach if you run it through with the following output, what do you see?

```auto
output { stdout { codec => rubydebug } }
```

---

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 14, 2018, 2:24pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/4 "2018-04-14T14:24:36Z")

</div>

@Mike.Barretta The output shows the same as what I see in Kibana. There isn't anything extra that I can see that explains why it fails to parse.

---

<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: [April 14, 2018, 3:41pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/5 "2018-04-14T15:41:55Z")

</div>

> [@arisbanach](#):
>
> Any ideas why this is happened?

Date is an array. Try this (force\_array =\> false on the xml filter does not stop path making everything an array).

```auto
  date { match => ["date[0]", "yyyyMMdd"] target => "date" }

```

---

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 14, 2018, 4:02pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/6 "2018-04-14T16:02:34Z")

</div>

@Badger You're right! However, when I set `force_array => false` in the xml filter, it still outputs date as an array for some reason.

---

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 14, 2018, 4:07pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/7 "2018-04-14T16:07:05Z")

</div>

Actually, this might be related to the `xpath` value I'm using to pull it. This has been happening with other fields as well, so I'm guess I'm just not understanding something about xpaths. Is there a way that I can concatenate multiple matches so that the output isn't stored in an array? Or will I need to use a different filter afterward to do that?

---

<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: [April 14, 2018, 4:58pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/8 "2018-04-14T16:58:37Z")

</div>

force\_array =\> false works for store\_xml, but not for xpath. If you look at the [source](https://github.com/logstash-plugins/logstash-filter-xml/blob/master/lib/logstash/filters/xml.rb) it is not even referenced in the if @xpath block, just in the if @store\_xml block.

---

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 14, 2018, 5:08pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/9 "2018-04-14T17:08:01Z")

</div>

So would you say a good way to handle this is just use another filter after the xml filter to merge any fields that are arrays into non-arrays first?

---

<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: [April 14, 2018, 5:43pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/10 "2018-04-14T17:43:43Z")

</div>

Yes. I tend to do this for each field. It is ugly but effective.

```auto
if [fieldx] { mutate { replace => { "fieldx" => "%{[fieldx][0]}" } } }

```

---

<div class="post-metadata">

### Author: ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)
#### Post date: [April 14, 2018, 6:06pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/11 "2018-04-14T18:06:20Z")

</div>

Thanks! You're amazing! How long have you been doing this for, if you don't mind me asking? I don't know if there is a normal learning curve with Logstash or if I'm just slow.

---

<div class="post-metadata">

### Author: ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)
#### Post date: [April 14, 2018, 6:55pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/12 "2018-04-14T18:55:32Z")

</div>

Thanks for jumping in and help out!

---

<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: [May 12, 2018, 6:56pm UTC](https://discuss.elastic.co/t/date-parsing-problem/128030/13 "2018-05-12T18:56:01Z")

</div>

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