# Using a long value as a date

**URL:** <https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047>\
**Category:** Elasticsearch\
**Created:** [March 6, 2011, 7:02pm UTC](https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047 "2011-03-06T19:02:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvanBrusic](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@IvanBrusic](https://discuss.elastic.co/u/IvanBrusic)\
**Post date:** [March 6, 2011, 7:02pm UTC](https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047/1 "2011-03-06T19:02:35Z")

</div>

Currently, the only format supported for the date mapping are those  
defined by JodaTime. Would it be possible have documents where the  
date fields are defined by longs (milliseconds)? In other words,  
storing the value without the need for a parser.

I knew it would return an error, but I still attempted to do so out of  
curiosity.

curl -XPUT '[http://127.0.0.1:9200/someindex/sometype/\_mapping](http://127.0.0.1:9200/someindex/sometype/_mapping)' -d '  
{  
"sometype" : {  
"properties" : {  
"mtime" : {  
"type" : "date"  
}  
}  
}  
}  
'

{"error":"MergeMappingException[Merge failed with failures {[mapper  
[mtime] of different type, current\_type [long], merged\_type  
[date]]}]","status":400}

I have no control over the JSON being indexed. The goal is to index  
any JSON document passed in with a predefined external mapping.

---

<div class="post-metadata">

**Author:** ![IvanBrusic](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@IvanBrusic](https://discuss.elastic.co/u/IvanBrusic)\
**Post date:** [March 6, 2011, 9:27pm UTC](https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047/2 "2011-03-06T21:27:17Z")

</div>

Actually, it appears that the date histogram facet works well with  
unmapped long values. I assumed it would not work since the  
documentation states "A specific histogram facet that can work with  
date field types", but the field does not have to be date.

On Mar 6, 2:02 pm, Ivan Brusic [ivan\_bru...@yahoo.com](mailto:ivan_bru...@yahoo.com) wrote:

> Currently, the only format supported for the date mapping are those  
> defined by JodaTime. Would it be possible have documents where the  
> date fields are defined by longs (milliseconds)? In other words,  
> storing the value without the need for a parser.
> 
> I knew it would return an error, but I still attempted to do so out of  
> curiosity.
> 
> curl -XPUT '[http://127.0.0.1:9200/someindex/sometype/\_mapping](http://127.0.0.1:9200/someindex/sometype/_mapping)' -d '  
> {  
> "sometype" : {  
> "properties" : {  
> "mtime" : {  
> "type" : "date"  
> }  
> }  
> }}
> 
> '
> 
> {"error":"MergeMappingException[Merge failed with failures {[mapper  
> [mtime] of different type, current\_type [long], merged\_type  
> [date]]}]","status":400}
> 
> I have no control over the JSON being indexed. The goal is to index  
> any JSON document passed in with a predefined external mapping.

---

<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:** [March 7, 2011, 4:32am UTC](https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047/3 "2011-03-07T04:32:31Z")

</div>

Right, since internally it just works with long values of milliseconds since the epoch, you can actually run it on long type fields as well. Note, it is expected that those are UTC.  
On Sunday, March 6, 2011 at 11:27 PM, Ivan Brusic wrote:

> Actually, it appears that the date histogram facet works well with  
> unmapped long values. I assumed it would not work since the  
> documentation states "A specific histogram facet that can work with  
> date field types", but the field does not have to be date.
> 
> On Mar 6, 2:02 pm, Ivan Brusic [ivan\_bru...@yahoo.com](mailto:ivan_bru...@yahoo.com) wrote:
> 
> > Currently, the only format supported for the date mapping are those  
> > defined by JodaTime. Would it be possible have documents where the  
> > date fields are defined by longs (milliseconds)? In other words,  
> > storing the value without the need for a parser.
> > 
> > I knew it would return an error, but I still attempted to do so out of  
> > curiosity.
> > 
> > curl -XPUT '[http://127.0.0.1:9200/someindex/sometype/\_mapping](http://127.0.0.1:9200/someindex/sometype/_mapping)' -d '  
> > {  
> > "sometype" : {  
> > "properties" : {  
> > "mtime" : {  
> > "type" : "date"  
> > }  
> > }  
> > }}
> > 
> > '
> > 
> > {"error":"MergeMappingException[Merge failed with failures {[mapper  
> > [mtime] of different type, current\_type [long], merged\_type  
> > [date]]}]","status":400}
> > 
> > I have no control over the JSON being indexed. The goal is to index  
> > any JSON document passed in with a predefined external mapping.

---

<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:10am UTC](https://discuss.elastic.co/t/using-a-long-value-as-a-date/4047/4 "2017-07-06T04:10:41Z")

</div>


