我希望有一个循环遍历ArrayList的方法,并根据它的内容动态生成x个密钥过滤器
List<KeyedFilter> filters = new ArrayList<KeyedFilter>();
for (String a: b) {
filters.add(generateKeyedFilterFromList(a.key, a.value, a.buckets);
}
private KeyedFilter (generateKeyedFilterFromList(String key, String value, String[] buckets) {
KeyedFilter filter = new KeyedFilter(key,
QueryBuilder(value, buckets));
}
这会很好地返回KeyedFilters列表,但是我还没有找到将它应用于AggregationBuilder的方法(String,KeyedFilter ...)
AggregationBuilder agg = AggregationBuilders.filter("filterName", filters);
试了一个数组
KeyedFilter[] filterArray = new KeyedFilter[filters.size()];
filterArray = filters.toArray(filterArray);
AggregationBuilder agg = AggregationBuilders.filter("filterName", filterArray); // honestly I am not completely sure why this doesn't work here
答案 0 :(得分:1)
为回答我自己的问题道歉,但万一其他人有兴趣。以上实际上确实有效,这是导致它失败的另一个错误。