我试图通过弹性组,然后按优先级对弹性查询进行分组和分组。
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 );
但是最后一条语句给出了编译错误,指出 filter(aggFilter)
的“ FilterAggregationBuilder类型的filter(FilterBuilder)方法不适用于参数(BoolQueryBuilder)”答案 0 :(得分:0)
您可能正在使用旧版本的ES,我的胆量告诉我1.7或更早版本...
在这种情况下,您需要使用以下代码来创建aggFilter
:
BoolFilterBuilder aggFilter = FilterBuilders.boolFilter().must(FilterBuilders.termsFilter("Priority", priority));