0

I've an a successive set of aggregations in a search request :

"aggs": {
    "nested_max": {
        "nested": {
            "path": "questionResponses"
        },
        "aggs": {
            "filter_max": {
                "filter": {
                    "term": {
                        "questionResponses.key": "announcement.question.tri"
                }
            },
            "aggs": {
                "agg_max": {
                    "max": {
                        "field": "questionResponses.numericValue"
                    }
                }
            }
        }
    }
}

Can someone please help me translate this chunk of request to java code : what I've done (but doesn't work):

   NestedAggregationBuilder maxAggregation = 
AggregationBuilders.nested("nested_max", questionResponses)
                   .subAggregation(AggregationBuilders.filter("filter_max", QueryBuilders.termQuery("announcement.question.tri", "announcement.question.tri")))
                   .subAggregation(AggregationBuilders.max("agg_max").field("questionResponses.numericValue"));

1 Answer 1

1

You should add agg_max sub aggregation to filter_max aggs.

filterMax = AggregationBuilders.filter(....);
aggMax = AggregationBuilders.max("agg_max")..;

NestedAggregationBuilder maxAggregation = 
AggregationBuilders.nested("nested_max", questionResponses)
                   .subAggregation(aggFilterMax.subAggregation(aggMax));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.