Elasticsearch Java API client 8.7.1 does not have option to supply order for the composite term aggregation but it was available server lib.
Query runs fine in KIBANA but cannot build same in Java client library
{"from":0,"size":0,"query":{"bool":{"must":[{"query_string":{"query":"test","fields":["field1"]}}],"adjust_pure_negative":true,"boost":1}},"aggregations":{"db":{"composite":{"size":10,"sources":[{"example":{"terms":{"field":"ex.agg","missing_bucket":false,"order":"desc"}}}]}}}}
Just look at aggregation.
Java client Lib code snippet
final Map<String, CompositeAggregationSource> comAggrSrcMap = new HashMap<>();
CompositeAggregationSource compositeAggregationSource = new CompositeAggregationSource.Builder()
.terms(termsAggrBuilder ->
termsAggrBuilder
.field("ex.agg"))
.missingBucket(false)
).build();
comAggrSrcMap.put("example", compositeAggregationSource);
CompositeAggregation compAgg = new CompositeAggregation.Builder().size(10).sources(comAggrSrcMap):
}
Cannot add "order":"desc" in the termsAggrBuilder. it accepts order only NamedValue
termsAggrBuilder
.order(new NamedValue<>("_count", SortOrder.Desc))
But E throws Error.
this was working fine old lib and order bucket come back in high hit count ordered desc.
New Library code throws Error:
{
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[31:21] [terms] order doesn't support values of type: START_ARRAY"
}
],
"type": "x_content_parse_exception",
"reason": "[31:21] [composite] failed to parse field [sources]",
"caused_by": {
"type": "x_content_parse_exception",
"reason": "[31:21] [terms] order doesn't support values of type: START_ARRAY"
}
},
"status": 400
}
Looking forward to get some answer.