1
searchRequestBuilder.addAggregation(
            AggregationBuilders.nested("skuFilter").path("skus")
            .subAggregation(AggregationBuilders
                .filter("sizeFilterCondition")
                .filter(FilterBuilders.boolFilter().must(FilterBuilders.termsFilter("skus.gender", "Dad\'s", "Mom\'s")))
                .subAggregation(
                    AggregationBuilders.nested("sizeValues").path("skus.attribute")
                        .subAggregation(AggregationBuilders.terms("attributeId").field("skus.attribute.attribute_id").size(AGGREGATION_SIZE)
                            .subAggregation(AggregationBuilders.terms("attributeValue").field("skus.attribute.attribute_value").size(AGGREGATION_SIZE)))))
            .subAggregation(AggregationBuilders.terms("fromAge").field("skus.from_age").size(AGGREGATION_SIZE)
                .subAggregation(AggregationBuilders.terms("toAge").field("skus.to_age").size(AGGREGATION_SIZE)))
            .subAggregation(AggregationBuilders.terms("gender").field("skus.gender").size(AGGREGATION_SIZE))
            .subAggregation(AggregationBuilders.min("min_price").field("skus.sale_price"))
            .subAggregation(AggregationBuilders.max("max_price").field("skus.sale_price"))
    );

above is my Aggregation code

I am trying find docCount of gender as follow

Nested agg = searchResponse.getAggregations().get("skuFilter");
        StringTerms terms = (StringTerms) agg.getAggregations().getAsMap().get("gender");

    List<Bucket> termsList = terms.getBuckets();
    for (Bucket bucket : termsList) {
        System.out.println(bucket.getKey());
        System.out.println(bucket.getDocCount());
    }

I am getting irrelevant ans.

what I am doing wrong?

1 Answer 1

0

Change

Nested agg = searchResponse.getAggregations().get("skuFilter");  

to

Nested agg = searchResponse.getAggregations().getAsMap().get("skuFilter");
Sign up to request clarification or add additional context in comments.

1 Comment

This solution is not woking

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.