ES 5.0 migration problem aggregation order in java

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))

1 Like

I finally solved the problem by replacing

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

by

order(Terms.Order.term(true))

1 Like

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