Skip to content

Invalid query generated when a composite aggregation contains a terms aggregation with an order #238

Closed
@Scylanth

Description

@Scylanth

Java API client version

7.17.0

Java version

17

Elasticsearch Version

7.17.0

Problem description

Composite aggregations with a Terms aggregation source fails when it contains an order.

Code sample
new co.elastic.clients.elasticsearch.core.SearchRequest.Builder() .index(Arrays.asList(getIndexes(getIndexPrefixesFromParameters()))) .size(0) .aggregations( "composite", a -> a.composite( c -> c.sources(Collections.singletonMap("source1", new CompositeAggregationSource.Builder().terms( t -> t.field("test").order(Collections.singletonMap("_key", SortOrder.Asc)) ).build()) )));

Generated query
"aggregations": { "composite": { "composite": { "sources": [{ "source1": { "terms": { "field": "test", "order": [{ "_key": "asc" } ] } } } ] } } }, "size": 0 }

The order field is an array, which contradicts the documentation

It is possible to define the direction of the sort for each value source by setting order to asc (default value) or desc (descending order) directly in the value source definition

Note : The order method requires a map in that case, which works well when doing a terms aggregation, but a terms aggregation as a source in a composite aggregation does not seems to accept the same json structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions