# Sorting Problem, ClassCastException

**URL:** https://discuss.elastic.co/t/sorting-problem-classcastexception/18911
**Category:** Elasticsearch
**Created:** [July 25, 2014, 11:21pm UTC](https://discuss.elastic.co/t/sorting-problem-classcastexception/18911 "2014-07-25T23:21:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Curt\_Hu](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Curt\_Hu](https://discuss.elastic.co/u/Curt_Hu)
#### Post date: [July 25, 2014, 11:21pm UTC](https://discuss.elastic.co/t/sorting-problem-classcastexception/18911/1 "2014-07-25T23:21:08Z")

</div>

In my document I have field called created like "2014-07-25T06:02:00", the mappings is:  
created: {  
format: dateOptionalTime  
type: date  
}

Here with the range query on that is fine, but why sort on that field I got:  
{  
error: ReduceSearchPhaseException[Failed to execute phase [query], [reduce] ]; nested: ClassCastException[java.lang.Long cannot be cast to org.apache.lucene.util.BytesRef];  
status: 503  
}

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [July 26, 2014, 7:38am UTC](https://discuss.elastic.co/t/sorting-problem-classcastexception/18911/2 "2014-07-26T07:38:08Z")

</div>

Which ES version?

Jörg

On Sat, Jul 26, 2014 at 1:21 AM, Curt Hu [zhongting.hu@gmail.com](mailto:zhongting.hu@gmail.com) wrote:

> In my document I have field called created like "2014-07-25T06:02:00", the  
> mappings is:  
> created: {  
> format: dateOptionalTime  
> type: date  
> }
> 
> Here with the range query on that is fine, but why sort on that field I  
> got:  
> {  
> error: ReduceSearchPhaseException[Failed to execute phase [query], [reduce]  
> ]; nested: ClassCastException[java.lang.Long cannot be cast to  
> org.apache.lucene.util.BytesRef];  
> status: 503  
> }
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Sorting-Problem-ClassCastException-tp4060659.html](http://elasticsearch-users.115913.n3.nabble.com/Sorting-Problem-ClassCastException-tp4060659.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1406330468734-4060659.post%40n3.nabble.com](https://groups.google.com/d/msgid/elasticsearch/1406330468734-4060659.post%40n3.nabble.com)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFksqcbCRgRBem%2B9Wh%3De-6hH54cgSg%3DZs\_ecOLFLf63cA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFksqcbCRgRBem%2B9Wh%3De-6hH54cgSg%3DZs_ecOLFLf63cA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ian\_Harrigan](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@Ian\_Harrigan](https://discuss.elastic.co/u/Ian_Harrigan)
#### Post date: [August 6, 2014, 10:46am UTC](https://discuss.elastic.co/t/sorting-problem-classcastexception/18911/3 "2014-08-06T10:46:08Z")

</div>

> Im getting the exact same problem... ES version 1.2.1... If i use  
> something like this:

{  
"from" : 0,  
"size" : 10,  
"query" : {  
"match\_all" : { }  
}  
}

All fine... However, if i have a sort on it, eg:

{  
"from" : 0,  
"size" : 10,  
"query" : {  
"match\_all" : { }  
},  
"sort" : [ {  
"dateTime" : {  
"order" : "desc"  
}  
} ]  
}

Then i get:

[2014-08-06 12:31:01,685][DEBUG][action.search.type] [Maur-Konn] [  
portal-boots-2014-08][0]: Failed to execute [org.elasticsearch.action.search  
.SearchRequ  
est@558af98a] while moving to second phase  
java.lang.ClassCastException: java.lang.Long cannot be cast to org.apache.  
lucene.util.BytesRef  
at org.apache.lucene.util.BytesRef.compareTo(BytesRef.java:33)  
at org.apache.lucene.search.FieldComparator.compareValues(  
FieldComparator.java:221)  
at org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.  
lessThan(ShardFieldDocSortedHitQueue.java:118)  
at org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.  
lessThan(ShardFieldDocSortedHitQueue.java:35)  
at org.apache.lucene.util.PriorityQueue.insertWithOverflow(  
PriorityQueue.java:159)  
at org.elasticsearch.search.controller.SearchPhaseController.  
sortDocs(SearchPhaseController.java:360)  
at org.elasticsearch.search.controller.SearchPhaseController.  
sortDocs(SearchPhaseController.java:146)  
at org.elasticsearch.action.search.type.  
TransportSearchQueryThenFetchAction$AsyncAction.moveToSecondPhase(  
TransportSearchQueryThenFetchAction.java:85)  
at org.elasticsearch.action.search.type.  
TransportSearchTypeAction$BaseAsyncAction.innerMoveToSecondPhase(  
TransportSearchTypeAction.java:404)  
at org.elasticsearch.action.search.type.  
TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(  
TransportSearchTypeAction.java:198)  
at org.elasticsearch.action.search.type.  
TransportSearchTypeAction$BaseAsyncAction$1.onResult(  
TransportSearchTypeAction.java:174)  
at org.elasticsearch.action.search.type.  
TransportSearchTypeAction$BaseAsyncAction$1.onResult(  
TransportSearchTypeAction.java:171)  
at org.elasticsearch.search.action.SearchServiceTransportAction$23.  
run(SearchServiceTransportAction.java:526)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(  
ThreadPoolExecutor.java:1145)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(  
ThreadPoolExecutor.java:615)  
at java.lang.Thread.run(Thread.java:744)

This is something to do with using multiple indexes as when i use the query  
with the inquisitor plugin and a single index it works fine. Is there a  
work around for this? This is causing a major problem in our production  
environment.

Thanks in advance,  
Ian

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/50e58d06-14d6-4c22-80ad-9058c52f4eb2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/50e58d06-14d6-4c22-80ad-9058c52f4eb2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:10am UTC](https://discuss.elastic.co/t/sorting-problem-classcastexception/18911/4 "2017-07-06T01:10:29Z")

</div>


