# Error parsing timestamp

**URL:** <https://discuss.elastic.co/t/error-parsing-timestamp/275795>\
**Category:** Logstash\
**Created:** [June 14, 2021, 6:43am UTC](https://discuss.elastic.co/t/error-parsing-timestamp/275795 "2021-06-14T06:43:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lani/32/90246_2.png) [@lani](https://discuss.elastic.co/u/lani)\
**Post date:** [June 14, 2021, 6:43am UTC](https://discuss.elastic.co/t/error-parsing-timestamp/275795/1 "2021-06-14T06:43:53Z")

</div>

Hi everyone,

i have a weird log parsing error I failed to solve, maybe someone here can assist me.

I have a docker container shipping logs in this (simple?) format:

`2021-06-14 08:30:14 ERROR Some message`

I am shipping them to Logstash using filebeat with this config:

```auto
filebeat.autodiscover:
  providers:
    - type: docker
      templates:
        - condition:
            equals:
              docker.container.name: Home-Assistant
          config:
            - type: container
              paths:
                - /var/lib/docker/containers/${data.docker.container.id}/*.log

```

In Logstash my pipeline config looks like this:

```auto
filter {
    if [container][name] == "Home-Assistant" {
         grok {
             match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:message}" }
             # (%{DATA:thread}) \[%{DATA:class}\] (?<message>(.|\r|\n)*)
             overwrite => ["message"]
         }
    }
}

```

Parsing this line fails with "Could not index event to Elasticsearch." and the following log in Logstash.

```auto
"error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [timestamp] of type [date] in document with id 'c542CXoBwxcEamlAvRaR'. Preview of field's value: '2021-06-14 08:30:14'", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"failed to parse date field [2021-06-14 08:30:14] with format [strict_date_optional_time||epoch_millis]", "caused_by"=>{"type"=>"date_time_parse_exception", "reason"=>"Failed to parse with all enclosed parsers"}}}}}}

```

I understand that there is some problem parsing the timestamp but I have no idea why. Any help is appreciated.

P.S. : This line is parsed perfectly fine in grok debugger.

---

<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:** [June 14, 2021, 1:31pm UTC](https://discuss.elastic.co/t/error-parsing-timestamp/275795/2 "2021-06-14T13:31:01Z")

</div>

> [@lani](#):
>
> `"failed to parse date field [2021-06-14 08:30:14] with format [strict_date_optional_time||epoch_millis]"`

You have told elasticsearch (possibly deliberately, or possibly by accident) that [timestamp] should be a date. When elasticsearch tries to parse a date it accepts two different formats by default. One is epoch\_millis, which expects a long integer, the other is strict\_date\_optional\_time [which is](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html) a "generic ISO datetime parser, where the date must include the year at a minimum, and the time (separated by `T` ), is optional. Examples: `yyyy-MM-dd'T'HH:mm:ss.SSSZ` or `yyyy-MM-dd`"

"2021-06-14 08:30:14" does not match either of those.

If you have configured a template to tell elasticsearch that the [timestamp] field is a date, then you could adjust the template to tell it what format to expect.

Alternatively you could use a date filter to parse and overwrite the [timestamp] field (using the target option) and then logstash will send the field to elasticsearch as a long.

---

<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:** [July 12, 2021, 1:31pm UTC](https://discuss.elastic.co/t/error-parsing-timestamp/275795/3 "2021-07-12T13:31:27Z")

</div>

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