# Bug ? Elasticsearch 7 failing to parse custom date format

**URL:** <https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104>\
**Category:** Elasticsearch\
**Created:** [April 16, 2019, 2:17pm UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104 "2019-04-16T14:17:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [April 16, 2019, 2:17pm UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/1 "2019-04-16T14:17:25Z")

</div>

Hello,

I am unable to create an index using the following date format using the latest version of elasticsearch

```
PUT http://localhost:9200/demo HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length: 151
Host: localhost:9200

{
  "mappings": {
    "properties": {
      "date": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss aa"
      }
    }
  }
}

```

Below is the error returned

```
HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
content-length: 555

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Invalid format: [yyyy-MM-dd HH:mm:ss aa]: Too many pattern letters: a"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Invalid format: [yyyy-MM-dd HH:mm:ss aa]: Too many pattern letters: a","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: [yyyy-MM-dd HH:mm:ss aa]: Too many pattern letters: a","caused_by":{"type":"illegal_argument_exception","reason":"Too many pattern letters: a"}}},"status":400}

```

A sample value for the above format would be

> 11/16/2018 7:18:00 PM

The same format worked fine on v6.x, is this some bug in the latest version or is there a different format / syntax we need to switch onto.

Thanks,  
Vikas.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 17, 2019, 6:03am UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/2 "2019-04-17T06:03:07Z")

</div>

It looks like only a single a is supported by java - [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)

There's nothing in the docs to suggest this has changed, but I did test between 6.X and 7.X and it was rejected in both.

---

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [April 17, 2019, 9:15am UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/3 "2019-04-17T09:15:17Z")

</div>

Well it does look like a bug introduced in 7, i could create a mapping using the following request on 6.6.2

```
PUT http://localhost:9200/demo HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length: 166
Host: localhost:9200

{
  "mappings": {
"_doc" : {
    "properties": {
      "date": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss aa"
      }
    }
  }
}
}

```

Response was

```
HTTP/1.1 200 OK
Warning: 299 Elasticsearch-6.6.2-3bd3e59 "the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template" "Wed, 17 Apr 2019 09:12:11 GMT"
content-type: application/json; charset=UTF-8
content-length: 63

{"acknowledged":true,"shards_acknowledged":true,"index":"demo"}

```

Also, yes it does work if you remove the "a" which would result in an incorrect date format.

---

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [April 17, 2019, 9:19am UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/4 "2019-04-17T09:19:43Z")

</div>

> [@warkolm](#):
>
> There's nothing in the docs to suggest this has changed

There was a change in v7 though [https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking\_70\_java\_time\_changes](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking_70_java_time_changes)

---

<div class="post-metadata">

**Author:** ![Vikas\_Mestry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_mestry/32/42301_2.png) [@Vikas\_Mestry](https://discuss.elastic.co/u/Vikas_Mestry)\
**Post date:** [April 17, 2019, 12:35pm UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/5 "2019-04-17T12:35:22Z")

</div>

Maybe this is an issue already [https://github.com/elastic/elasticsearch/issues/40913](https://github.com/elastic/elasticsearch/issues/40913)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 17, 2019, 9:17pm UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/6 "2019-04-17T21:17:47Z")

</div>

Yeah, I likely missed that.

---

<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 15, 2019, 9:17pm UTC](https://discuss.elastic.co/t/bug-elasticsearch-7-failing-to-parse-custom-date-format/177104/7 "2019-05-15T21:17:47Z")

</div>

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