# Joda date format error

**URL:** https://discuss.elastic.co/t/joda-date-format-error/2937
**Category:** Elasticsearch
**Created:** [May 3, 2010, 1:40pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937 "2010-05-03T13:40:12Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Mahendra\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahendra_m/32/3128_2.png) [@Mahendra\_M](https://discuss.elastic.co/u/Mahendra_M)
#### Post date: [May 3, 2010, 1:40pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/1 "2010-05-03T13:40:12Z")

</div>

Hi,

While applying mappings for a date field, I tried the following in the  
date\_formats field.  
"MM/yyyy", "yyyy/MM/dd HH:mm:ss"

When I submitted content for indexing, this format was generating an error.

java.lang.IllegalArgumentException: Invalid format: "05/2010" is  
malformed at "/2010"  
at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:634)

In the second case, it was "2010/05/03 10:43:00" is malformed at "/05/03"

I noticed that this error is coming up for formats where a slash (/)  
is used like yyyy/MM/dd or MM/yyyy

From the Joda documentation and some examples, I figured that formats  
like this are valid.

Could this possibly be a bug somewhere or am I missing something ?

Regards,  
Mahendra

[http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 3, 2010, 2:09pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/2 "2010-05-03T14:09:30Z")

</div>

Hi,

Can you post the mapping you use?

cheers,  
shay.banon

On May 3, 4:40 pm, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:

> Hi,
> 
> While applying mappings for a date field, I tried the following in the  
> date\_formats field.  
> "MM/yyyy", "yyyy/MM/dd HH:mm:ss"
> 
> When I submitted content for indexing, this format was generating an error.
> 
> java.lang.IllegalArgumentException: Invalid format: "05/2010" is  
> malformed at "/2010"  
> at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:6 34)
> 
> In the second case, it was "2010/05/03 10:43:00" is malformed at "/05/03"
> 
> I noticed that this error is coming up for formats where a slash (/)  
> is used like yyyy/MM/dd or MM/yyyy
> 
> From the Joda documentation and some examples, I figured that formats  
> like this are valid.
> 
> Could this possibly be a bug somewhere or am I missing something ?
> 
> Regards,  
> Mahendra
> 
> [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![Mahendra\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahendra_m/32/3128_2.png) [@Mahendra\_M](https://discuss.elastic.co/u/Mahendra_M)
#### Post date: [May 3, 2010, 4:27pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/3 "2010-05-03T16:27:04Z")

</div>

On Mon, May 3, 2010 at 7:39 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> Hi,
> 
> Can you post the mapping you use?

Hi,

The JSON is as follows - this is a test one. The field 'genre' is  
marked as date.

{  
"a" : {  
"type" : "object",  
"dynamic" : false,  
"enabled" : true,  
"path" : "full",  
"date\_formats" : ["yyyy/MM/dd"],  
"\_boost" : {  
"name" : "\_boost"  
},  
"\_id" : {  
"store" : "no"  
},  
"\_all" : {  
"enabled" : true,  
"store" : "no",  
"term\_vector" : "no"  
},  
"\_source" : {  
"name" : "\_source",  
"enabled" : true  
},  
"properties" : {  
"genre" : {  
"type" : "date",  
"date\_formats" : ["yyyy/MM/dd"],  
"index\_name" : "genre",  
"index" : "analyzed",  
"store" : "no",  
"term\_vector" : "no",  
"boost" : 1.0,  
"omit\_norms" : false,  
"include\_in\_all": false,  
"omit\_term\_freq\_and\_positions" : false  
},  
"sub\_genre" : {  
"type" : "string",  
"index\_name" : "sub\_genre",  
"index" : "analyzed",  
"store" : "no",  
"term\_vector" : "no",  
"boost" : 1.0,  
"omit\_norms" : false,  
"include\_in\_all": false,  
"omit\_term\_freq\_and\_positions" : false  
}  
}  
}  
}

The following content fails here:  
{  
"genre": "2010/05/03",  
"sub\_genre": "test"  
}

PS: I am trying this on elasticsearch 0.6

Regards,  
Mahendra

[http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![Mahendra\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahendra_m/32/3128_2.png) [@Mahendra\_M](https://discuss.elastic.co/u/Mahendra_M)
#### Post date: [May 4, 2010, 8:19am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/4 "2010-05-04T08:19:41Z")

</div>

Hi,

How I made the JSON was like this.

- Index a document without any mappings.
- Check elasticsearch logs for the mappings that were generated dynamically.
- Modify the mappings according to my needs.

I hope this is the correct approach..

Regards,  
Mahendra

On Mon, May 3, 2010 at 9:57 PM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:

> Hi,
> 
> The JSON is as follows - this is a test one. The field 'genre' is  
> marked as date.
> 
> {  
> "a" : {  
> "type" : "object",  
> "dynamic" : false,  
> "enabled" : true,  
> "path" : "full",  
> "date\_formats" : ["yyyy/MM/dd"],  
> "\_boost" : {  
> "name" : "\_boost"  
> },  
> "\_id" : {  
> "store" : "no"  
> },  
> "\_all" : {  
> "enabled" : true,  
> "store" : "no",  
> "term\_vector" : "no"  
> },  
> "\_source" : {  
> "name" : "\_source",  
> "enabled" : true  
> },  
> "properties" : {  
> "genre" : {  
> "type" : "date",  
> "date\_formats" : ["yyyy/MM/dd"],  
> "index\_name" : "genre",  
> "index" : "analyzed",  
> "store" : "no",  
> "term\_vector" : "no",  
> "boost" : 1.0,  
> "omit\_norms" : false,  
> "include\_in\_all": false,  
> "omit\_term\_freq\_and\_positions" : false  
> },  
> "sub\_genre" : {  
> "type" : "string",  
> "index\_name" : "sub\_genre",  
> "index" : "analyzed",  
> "store" : "no",  
> "term\_vector" : "no",  
> "boost" : 1.0,  
> "omit\_norms" : false,  
> "include\_in\_all": false,  
> "omit\_term\_freq\_and\_positions" : false  
> }  
> }  
> }  
> }
> 
> The following content fails here:  
> {  
> "genre": "2010/05/03",  
> "sub\_genre": "test"  
> }
> 
> PS: I am trying this on elasticsearch 0.6
> 
> Regards,  
> Mahendra
> 
> [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 4, 2010, 12:26pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/5 "2010-05-04T12:26:43Z")

</div>

Hi,

The mapping for specifying a format on a date field is called 'format' not  
'data\_formats'. The 'date\_formats' only applies to the object mapping, and  
is relevant when a new field is introduced that has no mappings in order to  
try and derive if its a date type or not.

Regarding the automatic detection of date fields based on the object  
mapping, the format you specified in the `date_formats` section still won't  
make date types to be detected properly. This is since I also check for the  
existence of '-' or ':' in the string. This is because the date parser is  
too lenient and manages to parse things that should be string with just  
numbers in them ;). I will add the '/' to it as well while I think of a  
better way to work around this...

cheers,  
shay.banon

On Tue, May 4, 2010 at 11:19 AM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:

> Hi,
> 
> How I made the JSON was like this.
> 
> - Index a document without any mappings.
> - Check elasticsearch logs for the mappings that were generated  
> dynamically.
> - Modify the mappings according to my needs.
> 
> I hope this is the correct approach..
> 
> Regards,  
> Mahendra
> 
> On Mon, May 3, 2010 at 9:57 PM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:
> 
> > Hi,
> > 
> > The JSON is as follows - this is a test one. The field 'genre' is  
> > marked as date.
> > 
> > {  
> > "a" : {  
> > "type" : "object",  
> > "dynamic" : false,  
> > "enabled" : true,  
> > "path" : "full",  
> > "date\_formats" : ["yyyy/MM/dd"],  
> > "\_boost" : {  
> > "name" : "\_boost"  
> > },  
> > "\_id" : {  
> > "store" : "no"  
> > },  
> > "\_all" : {  
> > "enabled" : true,  
> > "store" : "no",  
> > "term\_vector" : "no"  
> > },  
> > "\_source" : {  
> > "name" : "\_source",  
> > "enabled" : true  
> > },  
> > "properties" : {  
> > "genre" : {  
> > "type" : "date",  
> > "date\_formats" : ["yyyy/MM/dd"],  
> > "index\_name" : "genre",  
> > "index" : "analyzed",  
> > "store" : "no",  
> > "term\_vector" : "no",  
> > "boost" : 1.0,  
> > "omit\_norms" : false,  
> > "include\_in\_all": false,  
> > "omit\_term\_freq\_and\_positions" : false  
> > },  
> > "sub\_genre" : {  
> > "type" : "string",  
> > "index\_name" : "sub\_genre",  
> > "index" : "analyzed",  
> > "store" : "no",  
> > "term\_vector" : "no",  
> > "boost" : 1.0,  
> > "omit\_norms" : false,  
> > "include\_in\_all": false,  
> > "omit\_term\_freq\_and\_positions" : false  
> > }  
> > }  
> > }  
> > }
> > 
> > The following content fails here:  
> > {  
> > "genre": "2010/05/03",  
> > "sub\_genre": "test"  
> > }
> > 
> > PS: I am trying this on elasticsearch 0.6
> > 
> > Regards,  
> > Mahendra
> > 
> > [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![Mahendra\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahendra_m/32/3128_2.png) [@Mahendra\_M](https://discuss.elastic.co/u/Mahendra_M)
#### Post date: [May 5, 2010, 6:16am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/6 "2010-05-05T06:16:25Z")

</div>

On Tue, May 4, 2010 at 5:56 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> I will add the '/' to it as well while I think of a  
> better way to work around this...

That would be cool. I am actually writing a couchdb module to  
integrate it with elasticsearch (will apply to my company for  
opensourcing it). All of couchdb examples and documents use the date  
fields with a '/' (saying parsing it is easy in JS)

Format is : yyyy/MM/dd HH:mm:ss +SSSS

Having support for this will make couchdb integration a lot smoother.

Regards,  
Mahendra

[http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 5, 2010, 8:27am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/7 "2010-05-05T08:27:07Z")

</div>

Already in master (the support for auto detection of date fields with '/'),  
but, still the default date\_formats for objects is the ISO one, we can make  
the integration even smoother if I add this format to the list of default  
date\_formats if none are specified... .

On Wed, May 5, 2010 at 9:16 AM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:

> On Tue, May 4, 2010 at 5:56 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)  
> wrote:
> 
> > I will add the '/' to it as well while I think of a  
> > better way to work around this...
> 
> That would be cool. I am actually writing a couchdb module to  
> integrate it with elasticsearch (will apply to my company for  
> opensourcing it). All of couchdb examples and documents use the date  
> fields with a '/' (saying parsing it is easy in JS)
> 
> Format is : yyyy/MM/dd HH:mm:ss +SSSS
> 
> Having support for this will make couchdb integration a lot smoother.
> 
> Regards,  
> Mahendra
> 
> [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 5, 2010, 8:41am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/8 "2010-05-05T08:41:48Z")

</div>

By the way, where in couchdb does is this format specified, I can't find it.  
It seems like it all depends on how you input the string that represents the  
date...

On Wed, May 5, 2010 at 11:27 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Already in master (the support for auto detection of date fields with '/'),  
> but, still the default date\_formats for objects is the ISO one, we can make  
> the integration even smoother if I add this format to the list of default  
> date\_formats if none are specified... .
> 
> On Wed, May 5, 2010 at 9:16 AM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:
> 
> > On Tue, May 4, 2010 at 5:56 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)  
> > wrote:
> > 
> > > I will add the '/' to it as well while I think of a  
> > > better way to work around this...
> > 
> > That would be cool. I am actually writing a couchdb module to  
> > integrate it with elasticsearch (will apply to my company for  
> > opensourcing it). All of couchdb examples and documents use the date  
> > fields with a '/' (saying parsing it is easy in JS)
> > 
> > Format is : yyyy/MM/dd HH:mm:ss +SSSS
> > 
> > Having support for this will make couchdb integration a lot smoother.
> > 
> > Regards,  
> > Mahendra
> > 
> > [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![Mahendra\_M](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mahendra_m/32/3128_2.png) [@Mahendra\_M](https://discuss.elastic.co/u/Mahendra_M)
#### Post date: [May 5, 2010, 10:19am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/9 "2010-05-05T10:19:09Z")

</div>

On Wed, May 5, 2010 at 2:11 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> By the way, where in couchdb does is this format specified, I can't find it.  
> It seems like it all depends on how you input the string that represents the  
> date...

It is not mandatory. The examples are mostly in "/" format. In  
couchdb, the sorting happens based on string comparison. So, it does  
not matter if it is /,- or :

You can see some examples here:  
[http://books.couchdb.org/relax/design-documents/views](http://books.couchdb.org/relax/design-documents/views)

--  
Mahendra

[http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [May 5, 2010, 4:46pm UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/10 "2010-05-05T16:46:15Z")

</div>

Committed: [Mapper: Object mapper default 'date\_formats' to also support 'yyyy/MM/dd HH:mm:ss' and 'yyyy/MM/dd' · Issue #159 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/issue/159).

On Wed, May 5, 2010 at 1:19 PM, Mahendra M [mahendra.m@gmail.com](mailto:mahendra.m@gmail.com) wrote:

> On Wed, May 5, 2010 at 2:11 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)  
> wrote:
> 
> > By the way, where in couchdb does is this format specified, I can't find  
> > it.  
> > It seems like it all depends on how you input the string that represents  
> > the  
> > date...
> 
> It is not mandatory. The examples are mostly in "/" format. In  
> couchdb, the sorting happens based on string comparison. So, it does  
> not matter if it is /,- or :
> 
> You can see some examples here:  
> [http://books.couchdb.org/relax/design-documents/views](http://books.couchdb.org/relax/design-documents/views)
> 
> --  
> Mahendra
> 
> [http://twitter.com/mahendra](http://twitter.com/mahendra)

---

<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, 4:24am UTC](https://discuss.elastic.co/t/joda-date-format-error/2937/11 "2017-07-06T04:24:16Z")

</div>


