...
|
...
|
@@ -7,7 +7,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; |
|
|
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
...
|
...
|
@@ -18,23 +17,15 @@ import java.util.Map; |
|
|
*/
|
|
|
public abstract class UfoAbstractTokenAggregation extends AbstractAggregation {
|
|
|
|
|
|
protected int size;
|
|
|
|
|
|
private long minDocCount;
|
|
|
abstract String fieldName();
|
|
|
|
|
|
public UfoAbstractTokenAggregation() {
|
|
|
this.size = 10000;
|
|
|
this.minDocCount = 5;
|
|
|
}
|
|
|
abstract Integer size();
|
|
|
|
|
|
public UfoAbstractTokenAggregation(int size, long minDocCount) {
|
|
|
this.size = size;
|
|
|
this.minDocCount = minDocCount;
|
|
|
}
|
|
|
abstract Integer minDocCount();
|
|
|
|
|
|
@Override
|
|
|
public AbstractAggregationBuilder<?> getBuilder() {
|
|
|
return AggregationBuilders.terms(aggName()).field(fieldName()).size(size).minDocCount(minDocCount).includeExclude(new IncludeExclude(".{2,15}", null));
|
|
|
return AggregationBuilders.terms(aggName()).field(fieldName()).size(size()).minDocCount(minDocCount()).includeExclude(new IncludeExclude(".{2,15}", null));
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -44,15 +35,12 @@ public abstract class UfoAbstractTokenAggregation extends AbstractAggregation { |
|
|
return null;
|
|
|
}
|
|
|
|
|
|
Map<String, Integer> countMap = new LinkedHashMap<>(size);
|
|
|
Iterator<? extends MultiBucketsAggregation.Bucket> iterator = aggregation.getBuckets().iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
MultiBucketsAggregation.Bucket buck = iterator.next();
|
|
|
Map<String, Integer> countMap = new LinkedHashMap<>(size());
|
|
|
for (MultiBucketsAggregation.Bucket buck : aggregation.getBuckets()) {
|
|
|
countMap.put(buck.getKeyAsString(), Integer.valueOf(String.valueOf(buck.getDocCount())));
|
|
|
}
|
|
|
|
|
|
return countMap;
|
|
|
}
|
|
|
|
|
|
abstract String fieldName();
|
|
|
|
|
|
} |
...
|
...
|
|