# Error while sorting on fields which are not present for some of the documents

**URL:** <https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420>\
**Category:** Elasticsearch\
**Created:** [August 31, 2013, 9:27am UTC](https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420 "2013-08-31T09:27:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexei\_Petinov](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Alexei\_Petinov](https://discuss.elastic.co/u/Alexei_Petinov)\
**Post date:** [August 31, 2013, 9:27am UTC](https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420/1 "2013-08-31T09:27:19Z")

</div>

This issue is experienced on version 0.90.3  
Searching in two indexes with sort on two fields, for one of the indices  
one of the fields is present, for another - it is not. 'ignore\_unmapped' is  
set to true for both of the fields.

"sort" : [  
{  
"\_subtype": {  
"order": "desc",  
"ignore\_unmapped": true  
}  
},  
{  
"fileSize": {  
"order": "asc",  
"ignore\_unmapped": true  
}  
}  
]

The result for JSON search is:

{  
error: ReduceSearchPhaseException[Failed to execute phase [query],  
[reduce] ]; nested: ArrayIndexOutOfBoundsException[1];  
status: 500  
}

When searchhing with Java API:

org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
execute phase [query], [reduce]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeFetchPhase(TransportSearchDfsQueryThenFetchAction.java:172)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$3.onResult(TransportSearchDfsQueryThenFetchAction.java:150)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$3.onResult(TransportSearchDfsQueryThenFetchAction.java:144)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:176)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeQuery(TransportSearchDfsQueryThenFetchAction.java:144)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$2.run(TransportSearchDfsQueryThenFetchAction.java:131)  
~[elasticsearch-0.90.3.jar:na]  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
~[na:1.7.0\_25]  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
~[na:1.7.0\_25]  
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0\_25]  
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1  
at  
org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.lessThan(ShardFieldDocSortedHitQueue.java:118)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.lessThan(ShardFieldDocSortedHitQueue.java:35)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.apache.lucene.util.PriorityQueue.downHeap(PriorityQueue.java:247)  
~[lucene-core-4.4.0.jar:4.4.0 1504776 - sarowe - 2013-07-19 02:53:42]  
at org.apache.lucene.util.PriorityQueue.pop(PriorityQueue.java:184)  
~[lucene-core-4.4.0.jar:4.4.0 1504776 - sarowe - 2013-07-19 02:53:42]  
at  
org.elasticsearch.search.controller.SearchPhaseController.sortDocs(SearchPhaseController.java:281)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.innerExecuteFetchPhase(TransportSearchDfsQueryThenFetchAction.java:177)  
~[elasticsearch-0.90.3.jar:na]  
at  
org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeFetchPhase(TransportSearchDfsQueryThenFetchAction.java:170)  
~[elasticsearch-0.90.3.jar:na]  
... 8 common frames omitted

--  
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:** ![Alexei\_Petinov](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Alexei\_Petinov](https://discuss.elastic.co/u/Alexei_Petinov)\
**Post date:** [September 1, 2013, 12:56pm UTC](https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420/2 "2013-09-01T12:56:58Z")

</div>

To clarify: the whole query looks like that:

{  
"query": {  
"query\_string": {  
"query": "\_parents.$id:5223195f93f46463974aa1f4"  
}  
},  
"sort": [  
{  
"\_subtype": {  
"order": "desc",  
"ignore\_unmapped": true  
}  
},  
{  
"fileSize": {  
"order": "asc",  
"ignore\_unmapped": true  
}  
}  
]  
}

The request is run against 2 indices. The \_subtype field present for both  
indices. The fileSize field is present for only one of them. Interesting  
thing is that if I change fileSize field into some totally diffrerent  
field, which is not present in any index, for example fileSizeAAA, I do not  
get this error. If I omit one the \_subtype field, and leave only fileSize  
field, then I get another error:

{

- error: ReduceSearchPhaseException[Failed to execute phase [query],  
[reduce] ]; nested: ClassCastException[org.apache.lucene.search.ScoreDoc  
cannot be cast to org.apache.lucene.search.FieldDoc];
- status: 503

}

суббота, 31 августа 2013 г., 12:27:19 UTC+3 пользователь Alexei Petinov  
написал:

> This issue is experienced on version 0.90.3  
> Searching in two indexes with sort on two fields, for one of the indices  
> one of the fields is present, for another - it is not. 'ignore\_unmapped' is  
> set to true for both of the fields.
> 
> "sort" : [  
> {  
> "\_subtype": {  
> "order": "desc",  
> "ignore\_unmapped": true  
> }  
> },  
> {  
> "fileSize": {  
> "order": "asc",  
> "ignore\_unmapped": true  
> }  
> }  
> ]
> 
> The result for JSON search is:
> 
> {  
> error: ReduceSearchPhaseException[Failed to execute phase [query],  
> [reduce] ]; nested: ArrayIndexOutOfBoundsException[1];  
> status: 500  
> }
> 
> When searchhing with Java API:
> 
> org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to  
> execute phase [query], [reduce]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeFetchPhase(TransportSearchDfsQueryThenFetchAction.java:172)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$3.onResult(TransportSearchDfsQueryThenFetchAction.java:150)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$3.onResult(TransportSearchDfsQueryThenFetchAction.java:144)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:176)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeQuery(TransportSearchDfsQueryThenFetchAction.java:144)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction$2.run(TransportSearchDfsQueryThenFetchAction.java:131)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
> ~[na:1.7.0\_25]  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
> ~[na:1.7.0\_25]  
> at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0\_25]  
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 1  
> at  
> org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.lessThan(ShardFieldDocSortedHitQueue.java:118)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.search.controller.ShardFieldDocSortedHitQueue.lessThan(ShardFieldDocSortedHitQueue.java:35)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.apache.lucene.util.PriorityQueue.downHeap(PriorityQueue.java:247)  
> ~[lucene-core-4.4.0.jar:4.4.0 1504776 - sarowe - 2013-07-19 02:53:42]  
> at org.apache.lucene.util.PriorityQueue.pop(PriorityQueue.java:184)  
> ~[lucene-core-4.4.0.jar:4.4.0 1504776 - sarowe - 2013-07-19 02:53:42]  
> at  
> org.elasticsearch.search.controller.SearchPhaseController.sortDocs(SearchPhaseController.java:281)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.innerExecuteFetchPhase(TransportSearchDfsQueryThenFetchAction.java:177)  
> ~[elasticsearch-0.90.3.jar:na]  
> at  
> org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.executeFetchPhase(TransportSearchDfsQueryThenFetchAction.java:170)  
> ~[elasticsearch-0.90.3.jar:na]  
> ... 8 common frames omitted

--  
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:** ![Alexei\_Petinov](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@Alexei\_Petinov](https://discuss.elastic.co/u/Alexei_Petinov)\
**Post date:** [September 2, 2013, 12:46pm UTC](https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420/3 "2013-09-02T12:46:24Z")

</div>

> Just for information - it turns out there are limitations for using  
> ignore\_unmapped field in cross-index queries. See response to the issue  
> here:  
> [Error while sorting on fields which are not present for some of the documents · Issue #3599 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3599#issuecomment-23656373)

--  
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:18am UTC](https://discuss.elastic.co/t/error-while-sorting-on-fields-which-are-not-present-for-some-of-the-documents/13420/4 "2017-07-06T02:18:30Z")

</div>


