# Java.lang.IllegalArgumentException: Invalid format: "Fri Oct 09 02:06:12 +0000 2015"

**URL:** <https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [October 21, 2015, 3:01pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679 "2015-10-21T15:01:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 21, 2015, 3:01pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/1 "2015-10-21T15:01:32Z")

</div>

Hi:  
I am running ES 1.5.2 with the es-hadoop and es-spark versions 2.1.1 (with Spark 1.5.1 running in Local mode. )

My application can "successfully" connect and read the content. However when I try to do this :  
(The data I am trying to read is tweets that have been indexed in my instance). and I am trying to read the created\_at field which has the format : "Fri Oct 09 02:06:12 +0000 2015"  
So when I do this :

```
val firstDoc = esResults.first() 

```

I get the following error :

```
Caused by: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Cannot invoke method public org.joda.time.DateTime org.joda.time.format.DateTimeFormatter.parseDateTime(java.lang.String)

```

I looked at the issue that was closed : [https://github.com/elastic/elasticsearch-hadoop/issues/458](https://github.com/elastic/elasticsearch-hadoop/issues/458) and this was done as part of 2.1.0 (and so expecting it to be part of 2.1.1). But it does not seem to have fixed it all.

Any suggestion ?

here is the code snippet :  
val conf = new SparkConf().setAppName(this.getClass.getSimpleName).setMaster(master)  
conf.set("es.nodes","esHost")  
conf.set("es.port","7200")

val sc = new SparkContext(conf)

val esResults = sc.esRDD("tweets/twitter")

val firstDoc = esResults.first()

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [October 21, 2015, 3:31pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/2 "2015-10-21T15:31:33Z")

</div>

Can you post the full stack trace?  
The issue is that caused by the fact that the date you pass is not in [ISO8601 format](https://en.wikipedia.org/wiki/ISO_8601). The bug that you refer to doesn't apply here since in that case the data was obeying the ISO format.

P.S. Further more, in your case Joda library is detected and used instead which provides a richer and more lenient parsing yet it still fails.

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 21, 2015, 3:52pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/3 "2015-10-21T15:52:22Z")

</div>

as requested the full stack trace here is the gist :

> <https://gist.github.com/agastya71/73613e2182364b97e7c2>

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [October 21, 2015, 4:49pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/4 "2015-10-21T16:49:24Z")

</div>

Yup, the exception confirms it:

```auto
java.lang.IllegalArgumentException: Invalid format: "Fri Oct 09 02:06:12 +0000 2015"
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)

```

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 21, 2015, 4:57pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/5 "2015-10-21T16:57:08Z")

</div>

So, How do I get around this particular issue ? Do I need to write a custom parser and pass it in to deserialize the esRDD ?

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [October 21, 2015, 5:01pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/6 "2015-10-21T17:01:59Z")

</div>

I presume `created_at` is mapped at a `date` field with a custom date format right?  
That's why the connector tries to read this field as a date using the optionalTimeDate format (which the field clearly isn't obeying).

See this section of the [docs](https://www.elastic.co/guide/en/elasticsearch/hadoop/master/mapping.html#mapping-date) - it means adding the default format to the field.  
Any particular reason why you are not using the default ISO 8601 format?

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 21, 2015, 5:51pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/7 "2015-10-21T17:51:27Z")

</div>

The reason is that we want to preserve the original tweet as we received it without changing date formats and such.  
Thanks for the pointer about adding default formats.

Ramdev

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 21, 2015, 6:51pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/8 "2015-10-21T18:51:16Z")

</div>

Hi Costin:  
I am not able to figure out how to provide the Mapping I have to SparkConf so that the esRDD is able to map the right dateTimeFormat for the field in question. are there examples I can take a look at on how custom mapping is to be provided ?

Thanks much

Ramdev

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [December 16, 2015, 7:35pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/9 "2015-12-16T19:35:49Z")

</div>

Hi guys,

Any example about this?

Cheers,

---

<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 6, 2017, 1:26pm UTC](https://discuss.elastic.co/t/java-lang-illegalargumentexception-invalid-format-fri-oct-09-02-06-12-0000-2015/32679/10 "2017-07-06T13:26:55Z")

</div>


