本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation类的典型用法代码示例。如果您正苦于以下问题:Java MultiBucketsAggregation类的具体用法?Java MultiBucketsAggregation怎么用?Java MultiBucketsAggregation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiBucketsAggregation类属于org.elasticsearch.search.aggregations.bucket包,在下文中一共展示了MultiBucketsAggregation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reduce
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
public TResult reduce(ElasticsearchSearchQueryBase query, Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey) {
List<TBucket> buckets = new ArrayList<>();
for (Map.Entry<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKeyEntry : bucketsByKey.entrySet()) {
String key = bucketKeyToString(bucketsByKeyEntry.getKey());
long count = 0;
List<Aggregation> subAggs = new ArrayList<>();
for (MultiBucketsAggregation.Bucket b : bucketsByKeyEntry.getValue()) {
count += b.getDocCount();
for (Aggregation subAgg : b.getAggregations()) {
subAggs.add(subAgg);
}
}
Map<String, AggregationResult> nestedResults = reduceAggregationResults(query, getAggregationResultsByName(query, subAggs));
buckets.add(createBucket(key, count, nestedResults, bucketsByKeyEntry.getValue()));
}
return bucketsToResults(buckets);
}
示例2: reduce
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
@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<>();
double sum = 0;
for (Bucket bucket : buckets) {
Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], GapPolicy.INSERT_ZEROS);
sum += thisBucketValue;
List<InternalAggregation> aggs = StreamSupport.stream(bucket.getAggregations().spliterator(), false).map((p) -> {
return (InternalAggregation) p;
}).collect(Collectors.toList());
aggs.add(new InternalSimpleValue(name(), sum, formatter, new ArrayList<PipelineAggregator>(), metaData()));
Bucket newBucket = factory.createBucket(factory.getKey(bucket), bucket.getDocCount(), new InternalAggregations(aggs));
newBuckets.add(newBucket);
}
return factory.createAggregation(newBuckets);
}
示例3: writeOrder
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
public static void writeOrder(Terms.Order order, StreamOutput out) throws IOException {
if (order instanceof Aggregation) {
out.writeByte(order.id());
Aggregation aggregationOrder = (Aggregation) order;
out.writeBoolean(((MultiBucketsAggregation.Bucket.SubAggregationComparator) aggregationOrder.comparator).asc());
AggregationPath path = ((Aggregation) order).path();
out.writeString(path.toString());
} else if (order instanceof CompoundOrder) {
CompoundOrder compoundOrder = (CompoundOrder) order;
out.writeByte(order.id());
out.writeVInt(compoundOrder.orderElements.size());
for (Terms.Order innerOrder : compoundOrder.orderElements) {
Streams.writeOrder(innerOrder, out);
}
} else {
out.writeByte(order.id());
}
}
示例4: extractTerms
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
private Set<String> extractTerms(Aggregation aggregation) {
Set<String> terms = new HashSet<>();
if (aggregation instanceof MultiBucketsAggregation) {
for (MultiBucketsAggregation.Bucket bucket : ((MultiBucketsAggregation) (aggregation)).getBuckets()) {
if (bucket.getAggregations().asList().size() != 0) {
for (Aggregation agg : bucket.getAggregations().asList()) {
terms.addAll(extractTerms(agg));
}
} else {
terms.add(bucket.getKeyAsString());
}
}
} else {
throw new IllegalStateException("cannot deal with non bucket aggs");
}
return terms;
}
示例5: getAggregationByPath
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
public <T extends Aggregation> T getAggregationByPath(List<String> paths) {
this.checkAggs();
T agg = aggregations.get(paths.get(0));
for (int i = 1; i < paths.size(); i++) {
String attr = paths.get(i);
if(agg instanceof HasAggregations){
HasAggregations hasagg = (HasAggregations) agg;
agg = hasagg.getAggregations().get(attr);
}else if(agg instanceof MultiBucketsAggregation){
MultiBucketsAggregation magg = (MultiBucketsAggregation) agg;
if(magg.getBuckets().isEmpty()){
return agg;
}
Bucket bucket = magg.getBuckets().get(0);
agg = bucket.getAggregations().get(attr);
}else{
break;
}
}
return agg;
}
示例6: getAverageGeoPointFromBuckets
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
private static GeoPoint getAverageGeoPointFromBuckets(List<MultiBucketsAggregation.Bucket> buckets) {
List<GeoPoint> geoPoints = new ArrayList<>();
for (MultiBucketsAggregation.Bucket b : buckets) {
GeoHashGrid.Bucket gb = (GeoHashGrid.Bucket) b;
org.elasticsearch.common.geo.GeoPoint gp = (org.elasticsearch.common.geo.GeoPoint) gb.getKey();
geoPoints.add(new GeoPoint(gp.getLat(), gp.getLon()));
}
return GeoPoint.calculateCenter(geoPoints);
}
示例7: resolveBucketValue
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
public static Double resolveBucketValue(MultiBucketsAggregation agg,
InternalMultiBucketAggregation.Bucket bucket, List<String> aggPathAsList, GapPolicy gapPolicy) {
try {
Object propertyValue = bucket.getProperty(agg.getName(), aggPathAsList);
if (propertyValue == null) {
throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName()
+ " must reference either a number value or a single value numeric metric aggregation");
} else {
double value;
if (propertyValue instanceof Number) {
value = ((Number) propertyValue).doubleValue();
} else if (propertyValue instanceof InternalNumericMetricsAggregation.SingleValue) {
value = ((InternalNumericMetricsAggregation.SingleValue) propertyValue).value();
} else {
throw new AggregationExecutionException(AbstractPipelineAggregationBuilder.BUCKETS_PATH_FIELD.getPreferredName()
+ " must reference either a number value or a single value numeric metric aggregation, got: "
+ propertyValue.getClass().getCanonicalName());
}
// doc count never has missing values so gap policy doesn't apply here
boolean isDocCountProperty = aggPathAsList.size() == 1 && "_count".equals(aggPathAsList.get(0));
if (Double.isInfinite(value) || Double.isNaN(value) || (bucket.getDocCount() == 0 && !isDocCountProperty)) {
switch (gapPolicy) {
case INSERT_ZEROS:
return 0.0;
case SKIP:
default:
return Double.NaN;
}
} else {
return value;
}
}
} catch (InvalidAggregationPathException e) {
return null;
}
}
示例8: reduce
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
@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<>();
Number lastBucketKey = null;
Double lastBucketValue = null;
for (Bucket bucket : buckets) {
Number thisBucketKey = factory.getKey(bucket);
Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], gapPolicy);
if (lastBucketValue != null && thisBucketValue != null) {
double gradient = thisBucketValue - lastBucketValue;
double xDiff = -1;
if (xAxisUnits != null) {
xDiff = (thisBucketKey.doubleValue() - lastBucketKey.doubleValue()) / xAxisUnits;
}
final List<InternalAggregation> aggs = StreamSupport.stream(bucket.getAggregations().spliterator(), false).map((p) -> {
return (InternalAggregation) p;
}).collect(Collectors.toList());
aggs.add(new InternalDerivative(name(), gradient, xDiff, formatter, new ArrayList<PipelineAggregator>(), metaData()));
Bucket newBucket = factory.createBucket(factory.getKey(bucket), bucket.getDocCount(), new InternalAggregations(aggs));
newBuckets.add(newBucket);
} else {
newBuckets.add(bucket);
}
lastBucketKey = thisBucketKey;
lastBucketValue = thisBucketValue;
}
return factory.createAggregation(newBuckets);
}
示例9: createAggregation
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
@Override
public InternalAggregation createAggregation(List<MultiBucketsAggregation.Bucket> buckets) {
// convert buckets to the right type
List<Bucket> buckets2 = new ArrayList<>(buckets.size());
for (Object b : buckets) {
buckets2.add((Bucket) b);
}
buckets2 = Collections.unmodifiableList(buckets2);
return new InternalHistogram(name, buckets2, order, minDocCount, emptyBucketInfo, format,
keyed, pipelineAggregators(), getMetaData());
}
示例10: createAggregation
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
@Override
public InternalAggregation createAggregation(List<MultiBucketsAggregation.Bucket> buckets) {
// convert buckets to the right type
List<Bucket> buckets2 = new ArrayList<>(buckets.size());
for (Object b : buckets) {
buckets2.add((Bucket) b);
}
buckets2 = Collections.unmodifiableList(buckets2);
return new InternalDateHistogram(name, buckets2, order, minDocCount, offset, emptyBucketInfo, format,
keyed, pipelineAggregators(), getMetaData());
}
示例11: buildAggResponseMessage
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
private InterpreterResult buildAggResponseMessage(Aggregations aggregations) {
// Only the result of the first aggregation is returned
//
final Aggregation agg = aggregations.asList().get(0);
InterpreterResult.Type resType = InterpreterResult.Type.TEXT;
String resMsg = "";
if (agg instanceof InternalMetricsAggregation) {
resMsg = XContentHelper.toString((InternalMetricsAggregation) agg).toString();
}
else if (agg instanceof InternalSingleBucketAggregation) {
resMsg = XContentHelper.toString((InternalSingleBucketAggregation) agg).toString();
}
else if (agg instanceof InternalMultiBucketAggregation) {
final StringBuffer buffer = new StringBuffer("key\tdoc_count");
final InternalMultiBucketAggregation multiBucketAgg = (InternalMultiBucketAggregation) agg;
for (MultiBucketsAggregation.Bucket bucket : multiBucketAgg.getBuckets()) {
buffer.append("\n")
.append(bucket.getKeyAsString())
.append("\t")
.append(bucket.getDocCount());
}
resType = InterpreterResult.Type.TABLE;
resMsg = buffer.toString();
}
return new InterpreterResult(InterpreterResult.Code.SUCCESS, resType, resMsg);
}
示例12: getBuckets
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
static public List<? extends Bucket> getBuckets(Aggregation agg) {
if(agg instanceof MultiBucketsAggregation){
return ((MultiBucketsAggregation)agg).getBuckets();
}else{
return ImmutableList.of();
}
}
示例13: setAggregations
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
private void setAggregations(Aggregations aggregations, ActionResponse actionResp) {
// Only the result of the first aggregation is returned
//
final Aggregation agg = aggregations.asList().get(0);
if (agg instanceof InternalMetricsAggregation) {
actionResp.addAggregation(new AggWrapper(AggWrapper.AggregationType.SIMPLE,
XContentHelper.toString((InternalMetricsAggregation) agg).toString()));
}
else if (agg instanceof InternalSingleBucketAggregation) {
actionResp.addAggregation(new AggWrapper(AggWrapper.AggregationType.SIMPLE,
XContentHelper.toString((InternalSingleBucketAggregation) agg).toString()));
}
else if (agg instanceof InternalMultiBucketAggregation) {
final Set<String> headerKeys = new HashSet<>();
final List<Map<String, Object>> buckets = new LinkedList<>();
final InternalMultiBucketAggregation multiBucketAgg = (InternalMultiBucketAggregation) agg;
for (final MultiBucketsAggregation.Bucket bucket : multiBucketAgg.getBuckets()) {
try {
final XContentBuilder builder = XContentFactory.jsonBuilder();
bucket.toXContent(builder, null);
actionResp.addAggregation(
new AggWrapper(AggWrapper.AggregationType.MULTI_BUCKETS, builder.string()));
}
catch (final IOException e) {
// Ignored
}
}
}
}
示例14: LeafTraverse
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
public static void LeafTraverse(final ArrayList<Function> statsFields, final ArrayList<com.everdata.parser.AST_Stats.Bucket> bucketFields, Queue<List<String>> rows,
org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket node, Stack<String> path, int[] totalRows,
final int from, final int size) throws CommandException{
path.push(node.getKey());
MultiBucketsAggregation bucketAgg = node.getAggregations().get("statsWithBy");
if( bucketAgg != null ){
Iterator<? extends org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket> iterator = bucketAgg.getBuckets().iterator();
while (iterator.hasNext()) {
LeafTraverse(statsFields, bucketFields, rows, iterator.next(), path, totalRows, from, size);
}
}else{
if(size < 0 || totalRows[0] < (from + size) ){
List<String> row = new ArrayList<String>();
row.addAll(path);
Map<String, Aggregation> map = node.getAggregations().getAsMap();
for (Function f : statsFields) {
row.add(getValueFromAggregation(map.get(f.statsField), f));
}
row.add(String.valueOf(node.getDocCount()));
rows.add(row);
}
totalRows[0] += 1;
}
path.pop();
}
示例15: reduce
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入依赖的package包/类
@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 {
lagValue = lagWindow.peek(); // Peek here, because we rely on add'ing to always move the window
}
// 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);
}