use of org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createFacetList.
private static List<Facet> createFacetList(final SearchQuery searchQuery, final SearchResponse queryResponse) {
final List<Facet> facets = new ArrayList<>();
if (searchQuery.getFacetedQuery().isPresent() && queryResponse.getAggregations() != null) {
final FacetedQueryDefinition queryDefinition = searchQuery.getFacetedQuery().get().getDefinition();
for (final FacetDefinition facetDefinition : queryDefinition.getFacetDefinitions()) {
final Aggregation aggregation = obtainAggregation(queryResponse, facetDefinition.getName());
if (aggregation != null) {
final Facet facet = createFacet(facetDefinition, (MultiBucketsAggregation) aggregation);
facets.add(facet);
}
}
}
return facets;
}
use of org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation in project elasticsearch by elastic.
the class SerialDiffPipelineAggregator method reduce.
@Override
public InternalAggregation reduce(InternalAggregation aggregation, ReduceContext reduceContext) {
MultiBucketsAggregation histo = (MultiBucketsAggregation) aggregation;
List<? extends Bucket> buckets = histo.getBuckets();
HistogramFactory factory = (HistogramFactory) histo;
List<Bucket> newBuckets = new ArrayList<>();
EvictingQueue<Double> lagWindow = new EvictingQueue<>(lag);
int counter = 0;
for (Bucket bucket : buckets) {
Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], gapPolicy);
Bucket newBucket = bucket;
counter += 1;
// Still under the initial lag period, add nothing and move on
Double lagValue;
if (counter <= lag) {
lagValue = Double.NaN;
} else {
// Peek here, because we rely on add'ing to always move the window
lagValue = lagWindow.peek();
}
// Normalize null's to NaN
if (thisBucketValue == null) {
thisBucketValue = Double.NaN;
}
// Both have values, calculate diff and replace the "empty" bucket
if (!Double.isNaN(thisBucketValue) && !Double.isNaN(lagValue)) {
double diff = thisBucketValue - lagValue;
List<InternalAggregation> aggs = StreamSupport.stream(bucket.getAggregations().spliterator(), false).map((p) -> {
return (InternalAggregation) p;
}).collect(Collectors.toList());
aggs.add(new InternalSimpleValue(name(), diff, formatter, new ArrayList<PipelineAggregator>(), metaData()));
newBucket = factory.createBucket(factory.getKey(bucket), bucket.getDocCount(), new InternalAggregations(aggs));
}
newBuckets.add(newBucket);
lagWindow.add(thisBucketValue);
}
return factory.createAggregation(newBuckets);
}
use of org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createCluster.
private Map<FacetValue, DtList<I>> createCluster(final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
final Map<FacetValue, DtList<I>> resultCluster = new LinkedHashMap<>();
final FacetDefinition facetDefinition = searchQuery.getClusteringFacetDefinition();
final Aggregation facetAggregation = queryResponse.getAggregations().get(facetDefinition.getName());
if (facetDefinition.isRangeFacet()) {
// Cas des facettes par 'range'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final Bucket value = getBucketByKey(multiBuckets, facetRange.getListFilter().getFilterValue());
populateCluster(value, facetRange, resultCluster, dtcIndex, resultHighlights);
}
} else {
// Cas des facettes par 'term'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
FacetValue facetValue;
for (final Bucket bucket : multiBuckets.getBuckets()) {
final String term = bucket.getKeyAsString();
final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
final MessageText label = MessageText.of(term);
facetValue = new FacetValue(term, ListFilter.of(query), label);
populateCluster(bucket, facetValue, resultCluster, dtcIndex, resultHighlights);
}
}
return resultCluster;
}
use of org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createFacetList.
private static List<Facet> createFacetList(final SearchQuery searchQuery, final SearchResponse queryResponse) {
final List<Facet> facets = new ArrayList<>();
if (searchQuery.getFacetedQuery().isPresent() && queryResponse.getAggregations() != null) {
final FacetedQueryDefinition queryDefinition = searchQuery.getFacetedQuery().get().getDefinition();
for (final FacetDefinition facetDefinition : queryDefinition.getFacetDefinitions()) {
final Aggregation aggregation = queryResponse.getAggregations().get(facetDefinition.getName());
if (aggregation != null) {
final Facet facet = createFacet(facetDefinition, (MultiBucketsAggregation) aggregation);
facets.add(facet);
}
}
}
return facets;
}
Aggregations