{"action":"opened","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/35256","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/35256/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/35256/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/35256/events","html_url":"https://github.com/elastic/elasticsearch/issues/35256","id":377432596,"node_id":"MDU6SXNzdWUzNzc0MzI1OTY=","number":35256,"title":"Composite aggregation cannot be sorted by _key with bucket_sort pipeline aggregation","user":{"login":"ItamarBenjamin","id":7209981,"node_id":"MDQ6VXNlcjcyMDk5ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/7209981?v=4","gravatar_id":"","url":"https://api.github.com/users/ItamarBenjamin","html_url":"https://github.com/ItamarBenjamin","followers_url":"https://api.github.com/users/ItamarBenjamin/followers","following_url":"https://api.github.com/users/ItamarBenjamin/following{/other_user}","gists_url":"https://api.github.com/users/ItamarBenjamin/gists{/gist_id}","starred_url":"https://api.github.com/users/ItamarBenjamin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItamarBenjamin/subscriptions","organizations_url":"https://api.github.com/users/ItamarBenjamin/orgs","repos_url":"https://api.github.com/users/ItamarBenjamin/repos","events_url":"https://api.github.com/users/ItamarBenjamin/events{/privacy}","received_events_url":"https://api.github.com/users/ItamarBenjamin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-05T14:49:02Z","updated_at":"2018-11-05T14:49:02Z","closed_at":null,"author_association":"NONE","body":"<!-- Bug report -->\r\n\r\n**Elasticsearch version** : 6.4.2\r\n\r\n**Plugins installed**: []\r\n\r\n**JVM version**: openjdk 10.0.2\r\n\r\n**OS version** : UBUNTU-16.04 offical elastic docker\r\n\r\n**Description of the problem including expected versus actual behavior**:\r\n\r\nwhen running a composite aggregation and trying to sort on the aggregation keys, getting 503 and class cast exception.\r\n\r\n**Steps to reproduce**:\r\n\r\n`curl localhost:9200/reproduce -X PUT`\r\n\r\n`curl localhost:9200/reproduce/_doc/1 -X POST -H Content-Type:application/json -d '{ \"foo\" : 1, \"bar\" : 2}'`\r\n\r\n` curl localhost:9200/reproduce/_search -X POST -H Content-Type:application/json -d'{\r\n    \"aggs\": {\r\n        \"sales_per_month\": {\r\n            \"aggs\": {\r\n                \"sales_bucket_sort\": {\r\n                    \"bucket_sort\": {\r\n                        \"sort\": [\r\n                            {\r\n                                \"_key\": {\r\n                                    \"order\": \"asc\"\r\n                                }\r\n                            }\r\n                        ]\r\n                    }\r\n                }\r\n            },\r\n            \"composite\": {\r\n                \"sources\" : [\r\n                    { \"product\": { \"terms\" : { \"field\": \"foo\" } } }\r\n                ]\r\n            }\r\n        }\r\n    },\r\n    \"size\": 0\r\n}'\r\n`\r\n returns this error:\r\n`{\"error\":{\"root_cause\":[],\"type\":\"search_phase_execution_exception\",\"reason\":\"\",\"phase\":\"fetch\",\"grouped\":true,\"failed_shards\":[],\"caused_by\":{\"type\":\"class_cast_exception\",\"reason\":\"org.elasticsearch.search.aggregations.bucket.composite.InternalComposite$ArrayMap cannot be cast to java.base/java.lang.Comparable\"}},\"status\":503}`\r\n\r\n**Provide logs (if relevant)**:\r\n`\r\norg.elasticsearch.action.search.SearchPhaseExecutionException:\r\n        at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:293) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.FetchSearchPhase$1.onFailure(FetchSearchPhase.java:91) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadContext.java:708) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.4.2.jar:6.4.2]\r\n        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [?:?]\r\n        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]\r\n        at java.lang.Thread.run(Thread.java:844) [?:?]\r\nCaused by: java.lang.ClassCastException: org.elasticsearch.search.aggregations.bucket.composite.InternalComposite$ArrayMap cannot be cast to java.base/java.lang.Comparable\r\n        at org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregator$ComparableBucket.resolveAndCacheSortValues(BucketSortPipelineAggregator.java:137) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregator$ComparableBucket.<init>(BucketSortPipelineAggregator.java:129) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregator$ComparableBucket.<init>(BucketSortPipelineAggregator.java:120) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregator.reduce(BucketSortPipelineAggregator.java:103) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.search.aggregations.InternalAggregation.reduce(InternalAggregation.java:138) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:77) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.SearchPhaseController.reduceAggs(SearchPhaseController.java:525) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:502) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:419) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.SearchPhaseController$1.reduce(SearchPhaseController.java:738) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:101) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.FetchSearchPhase.access$000(FetchSearchPhase.java:44) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-6.4.2.jar:6.4.2]\r\n`\r\n"}}
{"actor":{"display_login":"ItamarBenjamin"}}