当前位置: 首页>>代码示例>>Java>>正文


Java MultiBucketsAggregation.Bucket方法代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket方法的典型用法代码示例。如果您正苦于以下问题:Java MultiBucketsAggregation.Bucket方法的具体用法?Java MultiBucketsAggregation.Bucket怎么用?Java MultiBucketsAggregation.Bucket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation的用法示例。


在下文中一共展示了MultiBucketsAggregation.Bucket方法的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);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:18,代码来源:ElasticsearchGraphQueryIterable.java

示例2: 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;
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:18,代码来源:StringFieldSignificantTermsSpecRequest.java

示例3: 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);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:10,代码来源:ElasticsearchGraphQueryIterable.java

示例4: 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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:InternalHistogram.java

示例5: 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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:InternalDateHistogram.java

示例6: 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);
  }
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:32,代码来源:ElasticsearchInterpreter.java

示例7: 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
      }
    }
  }
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:32,代码来源:TransportBasedClient.java

示例8: createAggregation

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
/** Create an {@link InternalAggregation} object that wraps the given buckets. */
InternalAggregation createAggregation(List<MultiBucketsAggregation.Bucket> buckets);
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:3,代码来源:HistogramFactory.java

示例9: getKey

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
@Override
public Number getKey(MultiBucketsAggregation.Bucket bucket) {
    return ((Bucket) bucket).key;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:InternalHistogram.java

示例10: handleAggregations

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
private  void handleAggregations(Aggregations aggregations, List<String> headers, List<List<String>> lines) throws CsvExtractorException {
    if(allNumericAggregations(aggregations)){
        lines.get(this.currentLineIndex).addAll(fillHeaderAndCreateLineForNumericAggregations(aggregations, headers));
        return;
    }
    //aggregations with size one only supported when not metrics.
    List<Aggregation> aggregationList = aggregations.asList();
    if(aggregationList.size() > 1){
        throw new CsvExtractorException("currently support only one aggregation at same level (Except for numeric metrics)");
    }
    Aggregation aggregation = aggregationList.get(0);
    //we want to skip singleBucketAggregations (nested,reverse_nested,filters)
    if(aggregation instanceof SingleBucketAggregation){
        Aggregations singleBucketAggs = ((SingleBucketAggregation) aggregation).getAggregations();
        handleAggregations(singleBucketAggs, headers, lines);
        return;
    }
    if(aggregation instanceof NumericMetricsAggregation){
        handleNumericMetricAggregation(headers, lines.get(currentLineIndex), aggregation);
        return;
    }
    if(aggregation instanceof GeoBounds){
        handleGeoBoundsAggregation(headers, lines, (GeoBounds) aggregation);
        return;
    }
    if(aggregation instanceof TopHits){
        //todo: handle this . it returns hits... maby back to normal?
        //todo: read about this usages
        // TopHits topHitsAggregation = (TopHits) aggregation;
    }
    if(aggregation instanceof MultiBucketsAggregation){
        MultiBucketsAggregation bucketsAggregation = (MultiBucketsAggregation) aggregation;
        String name = bucketsAggregation.getName();
        //checking because it can comes from sub aggregation again
        if(!headers.contains(name)){
            headers.add(name);
        }
        Collection<? extends MultiBucketsAggregation.Bucket> buckets = bucketsAggregation.getBuckets();

        //clone current line.
        List<String> currentLine = lines.get(this.currentLineIndex);
        List<String> clonedLine = new ArrayList<>(currentLine);

        //call handle_Agg with current_line++
        boolean firstLine = true;
        for (MultiBucketsAggregation.Bucket bucket : buckets) {
            //each bucket need to add new line with current line copied => except for first line
            String key = bucket.getKeyAsString();
            if(firstLine){
                firstLine = false;
            }
            else {
                currentLineIndex++;
                currentLine = new ArrayList<String>(clonedLine);
                lines.add(currentLine);
            }
            currentLine.add(key);
            handleAggregations(bucket.getAggregations(),headers,lines);

        }
    }

}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:64,代码来源:CSVResultsExtractor.java

示例11: handleAggregations

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
private void handleAggregations(Aggregations aggregations, List<String> headers, List<List<Object>> lines) throws ObjectResultsExtractException {
    if (allNumericAggregations(aggregations)) {
        lines.get(this.currentLineIndex).addAll(fillHeaderAndCreateLineForNumericAggregations(aggregations, headers));
        return;
    }
    //aggregations with size one only supported when not metrics.
    List<Aggregation> aggregationList = aggregations.asList();
    if (aggregationList.size() > 1) {
        throw new ObjectResultsExtractException("currently support only one aggregation at same level (Except for numeric metrics)");
    }
    Aggregation aggregation = aggregationList.get(0);
    //we want to skip singleBucketAggregations (nested,reverse_nested,filters)
    if (aggregation instanceof SingleBucketAggregation) {
        Aggregations singleBucketAggs = ((SingleBucketAggregation) aggregation).getAggregations();
        handleAggregations(singleBucketAggs, headers, lines);
        return;
    }
    if (aggregation instanceof NumericMetricsAggregation) {
        handleNumericMetricAggregation(headers, lines.get(currentLineIndex), aggregation);
        return;
    }
    if (aggregation instanceof GeoBounds) {
        handleGeoBoundsAggregation(headers, lines, (GeoBounds) aggregation);
        return;
    }
    if (aggregation instanceof TopHits) {
        //todo: handle this . it returns hits... maby back to normal?
        //todo: read about this usages
        // TopHits topHitsAggregation = (TopHits) aggregation;
    }
    if (aggregation instanceof MultiBucketsAggregation) {
        MultiBucketsAggregation bucketsAggregation = (MultiBucketsAggregation) aggregation;
        String name = bucketsAggregation.getName();
        //checking because it can comes from sub aggregation again
        if (!headers.contains(name)) {
            headers.add(name);
        }
        Collection<? extends MultiBucketsAggregation.Bucket> buckets = bucketsAggregation.getBuckets();

        //clone current line.
        List<Object> currentLine = lines.get(this.currentLineIndex);
        List<Object> clonedLine = new ArrayList<>(currentLine);

        //call handle_Agg with current_line++
        boolean firstLine = true;
        for (MultiBucketsAggregation.Bucket bucket : buckets) {
            //each bucket need to add new line with current line copied => except for first line
            String key = bucket.getKeyAsString();
            if (firstLine) {
                firstLine = false;
            } else {
                currentLineIndex++;
                currentLine = new ArrayList<Object>(clonedLine);
                lines.add(currentLine);
            }
            currentLine.add(key);
            handleAggregations(bucket.getAggregations(), headers, lines);

        }
    }

}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:63,代码来源:ObjectResultsExtractor.java

示例12: getKey

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
/** Get the key for the given bucket. Date histograms must return the
 *  number of millis since Epoch of the bucket key while numeric histograms
 *  must return the double value of the key. */
Number getKey(MultiBucketsAggregation.Bucket bucket);
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:HistogramFactory.java

示例13: createBucket

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
/** Create a {@link MultiBucketsAggregation.Bucket} object that wraps the
 *  given key, document count and aggregations. */
MultiBucketsAggregation.Bucket createBucket(Number key, long docCount, InternalAggregations aggregations);
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:HistogramFactory.java

示例14: createBucket

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
protected abstract TBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets); 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:2,代码来源:ElasticsearchGraphQueryIterable.java

示例15: extractValue

import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; //导入方法依赖的package包/类
Object extractValue(final String containingAggName, final MultiBucketsAggregation.Bucket bucket); 
开发者ID:metasfresh,项目名称:metasfresh-webui-api,代码行数:2,代码来源:KPIField.java


注:本文中的org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。