High level rest client composite aggregation ordering

Hi,

I am trying to write the following composite aggregation query using the High Level Rest Client, but cannot figure out how to specify the bucket sort part on the last_execution field:

curl -u elastic:pwd -v -H "Content-Type: application/json" -XPOST http://localhost:9200/myindex/_search?pretty=true -d '
{
   "query": {
         "bool": {
              "filter": [
                  { "range": { "updateDate" : { "gte": "now-30d"} } }
              ]
          } 
    },
    "aggs" : {
        "my_buckets": {
            "composite": {
                "size": 500,
                "sources" : [
                    { "clientId": { "terms": { "field": "clientId"} } },
                    { "orderId": { "terms": { "field": "oderId"} } },
                    { "orderState": { "terms": { "field": "orderState" } } }			   
                ]
            },
            "aggregations": {
                "last_execution": {  "max": { "field": "updateDate"  } },
                "last_execution_sort": { "bucket_sort": { "sort": [ { "last_execution": { "order": "desc" } } ] } }
            }
        }
    },
    "size": 0
}'

There doesn't seem to be a way to order on the CompositeAggregationBuilder?

Here is my current code:

                SearchRequest searchRequest = new SearchRequest(searchAliases);
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.size(0);
		BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
		searchSourceBuilder.query(boolQuery);
		searchRequest.source(searchSourceBuilder);
		
		// Add filters on boolQuery, removed because not relevant for this question
		
		List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();  
		
        TermsValuesSourceBuilder clientIdBucket = 
        		new TermsValuesSourceBuilder("clientId")  
                    .field("clientId");
        sources.add(clientIdBucket); 
        
        TermsValuesSourceBuilder orderIdBucket = 
        		new TermsValuesSourceBuilder("orderId")  
                    .field("orderId");
        sources.add(orderIdBucket);
        
        TermsValuesSourceBuilder orderStateBucket = 
        		new TermsValuesSourceBuilder("orderState")  
                    .field("orderState");
        sources.add(orderStateBucket);

        MaxAggregationBuilder maxAggregationBuilder = AggregationBuilders.max("last_update_date").field("updateDate");
        
        CompositeAggregationBuilder compositeAggregationBuilder =
                new CompositeAggregationBuilder("my_buckets", sources).
                size(1000).
                subAggregation(maxAggregationBuilder);
        
        searchSourceBuilder.aggregation(compositeAggregationBuilder);

Thanks,
Philippe

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