ES Java 动态添加键控过滤器到 AggregationBuilder
ES Java dynamically add keyed filters to AggregationBuilder
我想要一个循环遍历 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));
}
这个 return 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
很抱歉回答我自己的问题,但以防万一其他人有兴趣。以上确实有效,这是导致它失败的另一个错误。
我想要一个循环遍历 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));
}
这个 return 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
很抱歉回答我自己的问题,但以防万一其他人有兴趣。以上确实有效,这是导致它失败的另一个错误。