use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method getAggregationResultsByName.
private static Map<String, List<Aggregation>> getAggregationResultsByName(ElasticsearchSearchQueryBase query, Iterable<Aggregation> aggs) {
Map<String, List<Aggregation>> aggsByName = new HashMap<>();
if (aggs == null) {
return aggsByName;
}
for (Aggregation agg : aggs) {
if (agg.getName().equals(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME)) {
continue;
}
String aggName = query.getAggregationName(agg.getName());
List<Aggregation> l = aggsByName.computeIfAbsent(aggName, k -> new ArrayList<>());
l.add(agg);
}
return aggsByName;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceTermsResults.
private static TermsResult reduceTermsResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Terms) {
Terms h = (Terms) agg;
for (Terms.Bucket b : h.getBuckets()) {
TopHits exactMatchTopHits = b.getAggregations().get(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME);
String mapKey = bucketKeyToString(b.getKey(), exactMatchTopHits);
List<MultiBucketsAggregation.Bucket> existingBucketByName = bucketsByKey.computeIfAbsent(mapKey, k -> new ArrayList<>());
existingBucketByName.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a terms: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<TermsResult, TermsBucket>() {
@Override
protected TermsBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new TermsBucket(key, count, nestedResults);
}
@Override
protected TermsResult bucketsToResults(List<TermsBucket> buckets) {
return new TermsResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reducePercentilesResults.
private static PercentilesResult reducePercentilesResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
List<Percentile> results = new ArrayList<>();
if (aggs.size() != 1) {
throw new VertexiumException("Unexpected number of aggregations. Expected 1 but found: " + aggs.size());
}
Aggregation agg = aggs.get(0);
if (agg instanceof Percentiles) {
Percentiles percentiles = (Percentiles) agg;
StreamUtils.stream(percentiles).filter(percentile -> !Double.isNaN(percentile.getValue())).forEach(percentile -> results.add(new Percentile(percentile.getPercent(), percentile.getValue())));
} else {
throw new VertexiumException("Aggregation is not a percentile: " + agg.getClass().getName());
}
return new PercentilesResult(results);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceGeohashResults.
private static GeohashResult reduceGeohashResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof GeoHashGrid) {
GeoHashGrid h = (GeoHashGrid) agg;
for (GeoHashGrid.Bucket b : h.getBuckets()) {
List<MultiBucketsAggregation.Bucket> existingBucket = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
existingBucket.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a geohash: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<GeohashResult, GeohashBucket>() {
@Override
protected GeohashBucket createBucket(final Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
GeoPoint geoPoint = getAverageGeoPointFromBuckets(buckets);
return new GeohashBucket(key.toString(), count, geoPoint, nestedResults) {
@Override
public GeoRect getGeoCell() {
org.elasticsearch.common.geo.GeoPoint northWest = new org.elasticsearch.common.geo.GeoPoint();
org.elasticsearch.common.geo.GeoPoint southEast = new org.elasticsearch.common.geo.GeoPoint();
GeohashUtils.decodeCell(key.toString(), northWest, southEast);
return new GeoRect(new GeoPoint(northWest.getLat(), northWest.getLon()), new GeoPoint(southEast.getLat(), southEast.getLon()));
}
};
}
@Override
protected GeohashResult bucketsToResults(List<GeohashBucket> buckets) {
return new GeohashResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceHistogramResults.
private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().toString().equals("-1.0")) {
continue;
}
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {
@Override
protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new HistogramBucket(key, count, nestedResults);
}
@Override
protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
return new HistogramResult(buckets);
}
}.reduce(query, bucketsByKey);
}
Aggregations