# Adding "order" to a terms aggregator results in ArrayIndexOutOfBoundsException

**URL:** <https://discuss.elastic.co/t/adding-order-to-a-terms-aggregator-results-in-arrayindexoutofboundsexception/18242>\
**Category:** Elasticsearch\
**Created:** [June 20, 2014, 10:46pm UTC](https://discuss.elastic.co/t/adding-order-to-a-terms-aggregator-results-in-arrayindexoutofboundsexception/18242 "2014-06-20T22:46:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![debo](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@debo](https://discuss.elastic.co/u/debo)\
**Post date:** [June 20, 2014, 10:46pm UTC](https://discuss.elastic.co/t/adding-order-to-a-terms-aggregator-results-in-arrayindexoutofboundsexception/18242/1 "2014-06-20T22:46:46Z")

</div>

I have a simple document schema on which I am trying to run the following  
query :

curl -XPOST 'localhost:9200/indexName/topn/\_search?pretty' -d '{  
"aggregations" : {  
"applid" : {  
"terms" : {  
"field" : "applid",  
"size" : 3,  
"order" : {  
"tt\>byt\_sum" : "desc"  
}  
},  
"aggregations" : {  
"tt" : {  
"filter" : {  
"and" : {  
"filters" : [ {  
"range" : {  
"t" : {  
"from" : 1403211600000,  
"to" : 1403216100000,  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}, {  
"terms" : {  
"gid" : ["abcd"]  
}  
} ]  
}  
},  
"aggregations" : {  
"byt\_sum" : {  
"sum" : {  
"field" : "byt"  
}  
}  
}  
}  
}  
}  
}  
}'

This seems to give me back an error

"error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
all shards failed; shardFailures {[rcP5ncimTpmcUZgvn5cgSw][indexName][0]:  
ArrayIndexOutOfBoundsException[null]}{[vauVf2XOQvOobpqIbp0REQ][indexName][2]:  
RemoteTransportException[[Bloodstorm][inet[/10.0.0.91:9300]][search/phase/query]];  
nested: ArrayIndexOutOfBoundsException;  
}{[vauVf2XOQvOobpqIbp0REQ][indexName][1]:  
RemoteTransportException[[Bloodstorm][inet[/10.0.0.91:9300]][search/phase/query]];  
nested: ArrayIndexOutOfBoundsException;  
}{[vauVf2XOQvOobpqIbp0REQ][indexName][4]:  
RemoteTransportException[[Bloodstorm][inet[/10.0.0.91:9300]][search/phase/query]];  
nested: ArrayIndexOutOfBoundsException;  
}{[vauVf2XOQvOobpqIbp0REQ][indexName][3]:  
RemoteTransportException[[Bloodstorm][inet[/10.0.0.91:9300]][search/phase/query]];  
nested: ArrayIndexOutOfBoundsException; }]",  
"status" : 500  
}

When I take the  
"order" : {  
"tt\>byt\_sum" : "desc"  
}  
out, this seems to work fine. Also, the error only occurs for certain "gid"  
: ["abcd"] parameters. FOr example, it works for "gid" : ["1234"].  
Could you suggest what is going wrong here?

Elasticsearch version :

{  
"status" : 200,  
"name" : "Kylun",  
"version" : {  
"number" : "1.1.1",  
"build\_hash" : "f1585f096d3f3985e73456debdc1a0745f512bbc",  
"build\_timestamp" : "2014-04-16T14:27:12Z",  
"build\_snapshot" : false,  
"lucene\_version" : "4.7"  
},  
"tagline" : "You Know, for Search"  
}

--  
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/0aed2aa9-e91b-43db-b917-11612458da2a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0aed2aa9-e91b-43db-b917-11612458da2a%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:20am UTC](https://discuss.elastic.co/t/adding-order-to-a-terms-aggregator-results-in-arrayindexoutofboundsexception/18242/2 "2017-07-06T01:20:48Z")

</div>


