0

我正在尝试在弹性查询中进行分组和子分组,首先按 ipgroup,然后按优先级。

TermsBuilder ipGroupAgg = AggregationBuilders.terms("by_ipGroup").field("IP Group")
                .subAggregation(AggregationBuilders.terms("by_Priority").field("Priority"));
        // create the bool filter for the condition above
        String[] priority= { "2", "3" };
        BoolQueryBuilder aggFilter = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("Priority", priority));

        // create the filter aggregation and add the year sub-aggregation
        FilterAggregationBuilder aggregation = AggregationBuilders.filter("agg").filter(aggFilter).subAggregation(ipGroupAgg );

但是最后一条语句给出了编译错误,指出“FilterAggregationBuilder 类型中的方法过滤器(FilterBuilder)不适用于过滤器(aggFilter)的参数(BoolQueryBuilder)”

4

1 回答 1

0

您可能使用的是旧版本的 ES,我的胆量告诉我 1.7 或更早版本...在这种情况下,您需要使用以下代码来创建aggFilter

    BoolFilterBuilder aggFilter = FilterBuilders.boolFilter().must(FilterBuilders.termsFilter("Priority", priority));
于 2018-09-21T07:18:57.310 回答