# Getting date parsing exception for milliseconds in a query

**URL:** <https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029>\
**Category:** Elasticsearch\
**Created:** [February 17, 2016, 1:57pm UTC](https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029 "2016-02-17T13:57:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apanimesh061](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apanimesh061/32/927_2.png) [@apanimesh061](https://discuss.elastic.co/u/apanimesh061)\
**Post date:** [February 17, 2016, 1:57pm UTC](https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029/1 "2016-02-17T13:57:45Z")

</div>

I the settings of my index I have this field:

```
"publishedDate": {
  "type": "date",
  "format": "yyyy-MM-dd'T'HH:mm:ssZ",
  "store": true
}

```

And in a query I use that field in a Decay function like:

```
"gauss" : {
  "someField" : {
    "origin" : 1455710259655,
    "scale" : "200dd",
    "decay" : 0.2
  }
}

```

But I get the exception:

```
java.lang.IllegalArgumentException: Invalid format: "1455710259655" is malformed at "9655"

```

I tried to reproduce this error using `joda` which handles Date conversions in Elasticsearch:

```
Long currentMs = new DateTime().getMillis());
DateTimeFormatter currentMsTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
DateTime dt = currentMsTimeFormat.parseDateTime(String.valueOf(currentMs));
System.out.println(dt.toString());

```

This snippet also raises the same exception if `currentMs` is `1455710259655`.

I am using ES 2.1.1.

How to solve this issue?

---

<div class="post-metadata">

**Author:** ![dick1306](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@dick1306](https://discuss.elastic.co/u/dick1306)\
**Post date:** [March 10, 2016, 9:07am UTC](https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029/2 "2016-03-10T09:07:09Z")

</div>

I also met the same problem, can you tell me whether have been solved?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [March 10, 2016, 9:33am UTC](https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029/3 "2016-03-10T09:33:10Z")

</div>

The format parameter of the date field defines how your dates should be parsed. If you define a format like  
"yyyy-MM-dd'T'HH:mm:ssZ" then all your inputs for this field should follow this pattern. If you want to use the number of milliseconds since EPOCH you should use "epoch\_millis" as the format for your date field.  
You can check this page for further information:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html)

---

<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 5, 2017, 11:09pm UTC](https://discuss.elastic.co/t/getting-date-parsing-exception-for-milliseconds-in-a-query/42029/4 "2017-07-05T23:09:37Z")

</div>


