# ES 5.0 migration problem aggregation order in java

**URL:** https://discuss.elastic.co/t/es-5-0-migration-problem-aggregation-order-in-java/65890
**Category:** Elasticsearch
**Created:** [November 13, 2016, 12:56am UTC](https://discuss.elastic.co/t/es-5-0-migration-problem-aggregation-order-in-java/65890 "2016-11-13T00:56:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![biconou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/biconou/32/41612_2.png) [@biconou](https://discuss.elastic.co/u/biconou)
#### Post date: [November 13, 2016, 12:56am UTC](https://discuss.elastic.co/t/es-5-0-migration-problem-aggregation-order-in-java/65890/1 "2016-11-13T00:56:04Z")

</div>

Hi,

I'm migrating from ES 2.3 to 5.0.

I am coding the following aggregation using the java client api.

> "aggs" : {  
> "artist\_agg" : {  
> "terms" : { "field" : "artist",  
> "order" : { "\_term" : "asc" }},  
> "aggs" : {  
> "mediaType\_agg" : {  
> "terms" : { "field" : "mediaType"}  
> }  
> }  
> }  
> }

Note : The above JSON code works in both ES 2.3 and ES 5.0.

In ES 2.3 the following java code worked

> SearchResponse genresResponse = elasticSearchDaoHelper.getClient().prepareSearch(elasticSearchDaoHelper.indexNames(musicFolders))  
> .setQuery(QueryBuilders.typeQuery("MEDIA\_FILE"))  
> .addAggregation(AggregationBuilders.terms("artist\_agg").field("artist").order(Terms.Order.aggregation("\_term",true))  
> .subAggregation(AggregationBuilders.terms("mediaType\_agg").field("mediaType"))).setSize(0).get();

But with ES 5.0 I got the following error due to the order clause.

> Caused by: AggregationExecutionException[Invalid term-aggregator order path [\_term]. Unknown aggregation [\_term]]

I tried several things but no success. I can't figure out what string must replace the "\_term" here and the javadoc is too poor.

> order(Terms.Order.aggregation("\_term",true))

---

<div class="post-metadata">

### Author: ![biconou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/biconou/32/41612_2.png) [@biconou](https://discuss.elastic.co/u/biconou)
#### Post date: [November 13, 2016, 1:14am UTC](https://discuss.elastic.co/t/es-5-0-migration-problem-aggregation-order-in-java/65890/2 "2016-11-13T01:14:00Z")

</div>

I finally solved the problem by replacing

> order(Terms.Order.aggregation("\_term",true))

by

> order(Terms.Order.term(true))

---

<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: [December 11, 2016, 1:14am UTC](https://discuss.elastic.co/t/es-5-0-migration-problem-aggregation-order-in-java/65890/3 "2016-12-11T01:14:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
