# Date order working for "desc" and not for "asc"

**URL:** <https://discuss.elastic.co/t/date-order-working-for-desc-and-not-for-asc/14250>\
**Category:** Elasticsearch\
**Created:** [November 4, 2013, 9:50pm UTC](https://discuss.elastic.co/t/date-order-working-for-desc-and-not-for-asc/14250 "2013-11-04T21:50:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_Donovan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/r_donovan/32/26828_2.png) [@R\_Donovan](https://discuss.elastic.co/u/R_Donovan)\
**Post date:** [November 4, 2013, 9:50pm UTC](https://discuss.elastic.co/t/date-order-working-for-desc-and-not-for-asc/14250/1 "2013-11-04T21:50:30Z")

</div>

For a custom formatted date mapping.. I have a strange problem where the i  
get the expected result for "desc" but get the insertion result for "asc"??

For the hand crafted mapping .. with a custom date format

PUT test2/

{  
"test2": {  
"properties": {  
"event": {  
"time": {  
"type": "date",  
"store": "yes",  
"format": "yyyy/MM/dd HH:mm:ss.SSS",  
"index": "analyzed"  
},  
"eventKey": {  
"type": "string",  
"store": "yes",  
"index": "analyzed"  
},  
"channelid": {  
"type": "string",  
"store": "yes",  
"index": "analyzed"  
},  
"type": {  
"type": "string",  
"store": "yes",  
"index": "analyzed"  
},  
"line": {  
"type": "string",  
"store": "yes",  
"index": "analyzed"  
}  
}  
}  
}  
}

for the dates entered, that differ by seconds

"time": "2012/12/01 12:01:30.001",  
"time": "2012/12/01 12:01:32.001",  
"time": "2012/12/01 12:01:31.001",

the expected sorted order is returned for { "event.time" : {"order" :  
"desc"} however for {"order" : "asc"} it is returning the insertion  
order

I also not the sort values for "desc" are  
"sort": ["30.001"]  
"sort": ["31.001"]  
"sort": ["32.001"]

while for "asc"

"sort": ["01"]  
"sort": ["01"]  
"sort": ["01"]

Any solution or hints would be greatly appreciated

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 9:39am UTC](https://discuss.elastic.co/t/date-order-working-for-desc-and-not-for-asc/14250/2 "2013-11-14T09:39:35Z")

</div>

Hey,

your mapping seems wrong.. if you create a object hierarchy, you need to  
use the properties field as well, like this

curl -X PUT localhost:9200/test -d '  
{  
"test2": {  
"properties": {  
"event": {  
"properties": {  
"time": {  
"type": "date",  
"store": "yes",  
"format": "yyyy/MM/dd HH:mm:ss.SSS",  
"index": "analyzed"  
}  
}  
}  
}  
}  
}  
'

that should make it work.

--Alex

On Mon, Nov 4, 2013 at 10:50 PM, R Donovan [rdonovan2004@gmail.com](mailto:rdonovan2004@gmail.com) wrote:

> For a custom formatted date mapping.. I have a strange problem where the i  
> get the expected result for "desc" but get the insertion result for "asc"??
> 
> For the hand crafted mapping .. with a custom date format
> 
> PUT test2/
> 
> {  
> "test2": {  
> "properties": {  
> "event": {  
> "time": {  
> "type": "date",  
> "store": "yes",  
> "format": "yyyy/MM/dd HH:mm:ss.SSS",  
> "index": "analyzed"  
> },  
> "eventKey": {  
> "type": "string",  
> "store": "yes",  
> "index": "analyzed"  
> },  
> "channelid": {  
> "type": "string",  
> "store": "yes",  
> "index": "analyzed"  
> },  
> "type": {  
> "type": "string",  
> "store": "yes",  
> "index": "analyzed"  
> },  
> "line": {  
> "type": "string",  
> "store": "yes",  
> "index": "analyzed"  
> }  
> }  
> }  
> }  
> }
> 
> for the dates entered, that differ by seconds
> 
> "time": "2012/12/01 12:01:30.001",  
> "time": "2012/12/01 12:01:32.001",  
> "time": "2012/12/01 12:01:31.001",
> 
> the expected sorted order is returned for { "event.time" : {"order" :  
> "desc"} however for {"order" : "asc"} it is returning the insertion  
> order
> 
> I also not the sort values for "desc" are  
> "sort": ["30.001"]  
> "sort": ["31.001"]  
> "sort": ["32.001"]
> 
> while for "asc"
> 
> "sort": ["01"]  
> "sort": ["01"]  
> "sort": ["01"]
> 
> Any solution or hints would be greatly appreciated
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:07am UTC](https://discuss.elastic.co/t/date-order-working-for-desc-and-not-for-asc/14250/3 "2017-07-06T02:07:11Z")

</div>


