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


Java NumericMetricsAggregation类代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation的典型用法代码示例。如果您正苦于以下问题:Java NumericMetricsAggregation类的具体用法?Java NumericMetricsAggregation怎么用?Java NumericMetricsAggregation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NumericMetricsAggregation类属于org.elasticsearch.search.aggregations.metrics包,在下文中一共展示了NumericMetricsAggregation类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInBuckets

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
public void testInBuckets() throws Exception {

        SearchResponse searchResponse = client().prepareSearch("idx_hll")
                .setQuery(matchAllQuery())
                .addAggregation(AggregationBuilders.terms("tag")
                        .field("tag")
                        .subAggregation(new HyperUniqueSumAggregationBuilder("hyperlog").field("hll")))
                        .execute().actionGet();

        assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
        StringTerms stringTerms = searchResponse.getAggregations().get("tag");
        assertThat(stringTerms.getBuckets().size(), equalTo(2));
        NumericMetricsAggregation.SingleValue numericMetricsAggregation = stringTerms.getBucketByKey("crazy").getAggregations().get("hyperlog");
        assertThat(numericMetricsAggregation.value(), equalTo(100.0));
        numericMetricsAggregation = stringTerms.getBucketByKey("mayBeCrazy").getAggregations().get("hyperlog");
        assertThat(numericMetricsAggregation.value(), equalTo(110.0));

    }
 
开发者ID:bazaarvoice,项目名称:elasticsearch-hyperloglog,代码行数:19,代码来源:HyperLogLogPlusAggregationPluginTests.java

示例2: testEmptyAggregation

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
public void testEmptyAggregation() throws Exception {

        SearchResponse searchResponse = client().prepareSearch("idx_no_hll")
                .setQuery(matchAllQuery())
                .addAggregation(new HyperUniqueSumAggregationBuilder("hyperlog").field("hll"))
                .execute().actionGet();

        assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
        NumericMetricsAggregation.SingleValue numericMetricsAggregation = searchResponse.getAggregations().get("hyperlog");
        assertThat(numericMetricsAggregation, notNullValue());
        assertEquals("expected 0.0 ", "0.0", numericMetricsAggregation.getValueAsString());

    }
 
开发者ID:bazaarvoice,项目名称:elasticsearch-hyperloglog,代码行数:14,代码来源:HyperLogLogPlusAggregationPluginTests.java

示例3: testUniqueSum1

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
public void testUniqueSum1() throws Exception {

        SearchResponse searchResponse = client().prepareSearch("idx_hll")
                .setQuery(matchAllQuery())
                .addAggregation(new HyperUniqueSumAggregationBuilder("hyperlog").field("hll"))
                .execute().actionGet();

        assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
        NumericMetricsAggregation.SingleValue numericMetricsAggregation = searchResponse.getAggregations().get("hyperlog");
        assertThat(numericMetricsAggregation, notNullValue());
        assertThat(numericMetricsAggregation.value(), equalTo(110.0));

    }
 
开发者ID:bazaarvoice,项目名称:elasticsearch-hyperloglog,代码行数:14,代码来源:HyperLogLogPlusAggregationPluginTests.java

示例4: testUniqueSum2

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
public void testUniqueSum2() throws Exception {

        SearchResponse searchResponse = client().prepareSearch("idx_hll")
                .setQuery(termQuery("tag", "crazy"))
                .addAggregation(new HyperUniqueSumAggregationBuilder("hyperlog").field("hll"))
                .execute().actionGet();

        assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
        NumericMetricsAggregation.SingleValue numericMetricsAggregation = searchResponse.getAggregations().get("hyperlog");
        assertThat(numericMetricsAggregation, notNullValue());
        assertThat(numericMetricsAggregation.value(), equalTo(100.0));

    }
 
开发者ID:bazaarvoice,项目名称:elasticsearch-hyperloglog,代码行数:14,代码来源:HyperLogLogPlusAggregationPluginTests.java

示例5: allNumericAggregations

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
private  boolean allNumericAggregations(Aggregations aggregations) {
    List<Aggregation> aggregationList = aggregations.asList();
    for(Aggregation aggregation : aggregationList){
        if(!(aggregation instanceof NumericMetricsAggregation)){
            return false;
        }
    }
    return true;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:10,代码来源:CSVResultsExtractor.java

示例6: allNumericAggregations

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
private boolean allNumericAggregations(Aggregations aggregations) {
    List<Aggregation> aggregationList = aggregations.asList();
    for (Aggregation aggregation : aggregationList) {
        if (!(aggregation instanceof NumericMetricsAggregation)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:10,代码来源:ObjectResultsExtractor.java

示例7: handleAggregations

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的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

示例8: handleNumericMetricAggregation

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
private  void handleNumericMetricAggregation(List<String> header, List<String> line, Aggregation aggregation) throws CsvExtractorException {
    String name = aggregation.getName();

    if(aggregation instanceof NumericMetricsAggregation.SingleValue){
        if(!header.contains(name)){
            header.add(name);
        }
        line.add(((NumericMetricsAggregation.SingleValue) aggregation).getValueAsString());
    }
    //todo:Numeric MultiValue - Stats,ExtendedStats,Percentile...
    else if(aggregation instanceof NumericMetricsAggregation.MultiValue){
        if(aggregation instanceof Stats) {
            String[] statsHeaders = new String[]{"count", "sum", "avg", "min", "max"};
            boolean isExtendedStats = aggregation instanceof ExtendedStats;
            if(isExtendedStats){
                String[] extendedHeaders = new String[]{"sumOfSquares", "variance", "stdDeviation"};
                statsHeaders = Util.concatStringsArrays(statsHeaders,extendedHeaders);
            }
            mergeHeadersWithPrefix(header, name, statsHeaders);
            Stats stats = (Stats) aggregation;
            line.add(stats.getCountAsString());
            line.add(stats.getSumAsString());
            line.add(stats.getAvgAsString());
            line.add(stats.getMinAsString());
            line.add(stats.getMaxAsString());
            if(isExtendedStats){
                ExtendedStats extendedStats = (ExtendedStats) aggregation;
                line.add(extendedStats.getSumOfSquaresAsString());
                line.add(extendedStats.getVarianceAsString());
                line.add(extendedStats.getStdDeviationAsString());
            }
        }
        else if( aggregation instanceof Percentiles){
            String[] percentileHeaders = new String[]{"1.0", "5.0", "25.0", "50.0", "75.0", "95.0", "99.0"};
            mergeHeadersWithPrefix(header, name, percentileHeaders);
            Percentiles percentiles = (Percentiles) aggregation;
            line.add(percentiles.percentileAsString(1.0));
            line.add(percentiles.percentileAsString(5.0));
            line.add(percentiles.percentileAsString(25.0));
            line.add(percentiles.percentileAsString(50.0));
            line.add(percentiles.percentileAsString(75));
            line.add(percentiles.percentileAsString(95.0));
            line.add(percentiles.percentileAsString(99.0));
        }
        else {
            throw new CsvExtractorException("unknown NumericMetricsAggregation.MultiValue:" + aggregation.getClass());
        }

    }
    else {
        throw new CsvExtractorException("unknown NumericMetricsAggregation" + aggregation.getClass());
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:54,代码来源:CSVResultsExtractor.java

示例9: handleAggregations

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的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

示例10: handleNumericMetricAggregation

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
private void handleNumericMetricAggregation(List<String> header, List<Object> line, Aggregation aggregation) throws ObjectResultsExtractException {
    String name = aggregation.getName();

    if (aggregation instanceof NumericMetricsAggregation.SingleValue) {
        if (!header.contains(name)) {
            header.add(name);
        }
        line.add(((NumericMetricsAggregation.SingleValue) aggregation).value());
    }
    //todo:Numeric MultiValue - Stats,ExtendedStats,Percentile...
    else if (aggregation instanceof NumericMetricsAggregation.MultiValue) {
        if (aggregation instanceof Stats) {
            String[] statsHeaders = new String[]{"count", "sum", "avg", "min", "max"};
            boolean isExtendedStats = aggregation instanceof ExtendedStats;
            if (isExtendedStats) {
                String[] extendedHeaders = new String[]{"sumOfSquares", "variance", "stdDeviation"};
                statsHeaders = Util.concatStringsArrays(statsHeaders, extendedHeaders);
            }
            mergeHeadersWithPrefix(header, name, statsHeaders);
            Stats stats = (Stats) aggregation;
            line.add(stats.getCount());
            line.add(stats.getSum());
            line.add(stats.getAvg());
            line.add(stats.getMin());
            line.add(stats.getMax());
            if (isExtendedStats) {
                ExtendedStats extendedStats = (ExtendedStats) aggregation;
                line.add(extendedStats.getSumOfSquares());
                line.add(extendedStats.getVariance());
                line.add(extendedStats.getStdDeviation());
            }
        } else if (aggregation instanceof Percentiles) {
            String[] percentileHeaders = new String[]{"1.0", "5.0", "25.0", "50.0", "75.0", "95.0", "99.0"};
            mergeHeadersWithPrefix(header, name, percentileHeaders);
            Percentiles percentiles = (Percentiles) aggregation;
            line.add(percentiles.percentile(1.0));
            line.add(percentiles.percentile(5.0));
            line.add(percentiles.percentile(25.0));
            line.add(percentiles.percentile(50.0));
            line.add(percentiles.percentile(75));
            line.add(percentiles.percentile(95.0));
            line.add(percentiles.percentile(99.0));
        } else {
            throw new ObjectResultsExtractException("unknown NumericMetricsAggregation.MultiValue:" + aggregation.getClass());
        }

    } else {
        throw new ObjectResultsExtractException("unknown NumericMetricsAggregation" + aggregation.getClass());
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:51,代码来源:ObjectResultsExtractor.java

示例11: handleNumericMetricAggregation

import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; //导入依赖的package包/类
private  void handleNumericMetricAggregation(List<String> header, List<String> line, Aggregation aggregation) throws CsvExtractorException {
    String name = aggregation.getName();

    if(aggregation instanceof NumericMetricsAggregation.SingleValue){
        if(!header.contains(name)){
            header.add(name);
        }
        NumericMetricsAggregation.SingleValue agg = (NumericMetricsAggregation.SingleValue) aggregation;
        line.add(!Double.isInfinite(agg.value()) ? agg.getValueAsString() : "null");
    }
    //todo:Numeric MultiValue - Stats,ExtendedStats,Percentile...
    else if(aggregation instanceof NumericMetricsAggregation.MultiValue){
        if(aggregation instanceof Stats) {
            String[] statsHeaders = new String[]{"count", "sum", "avg", "min", "max"};
            boolean isExtendedStats = aggregation instanceof ExtendedStats;
            if(isExtendedStats){
                String[] extendedHeaders = new String[]{"sumOfSquares", "variance", "stdDeviation"};
                statsHeaders = Util.concatStringsArrays(statsHeaders,extendedHeaders);
            }
            mergeHeadersWithPrefix(header, name, statsHeaders);
            Stats stats = (Stats) aggregation;
            line.add(String.valueOf(stats.getCount()));
            line.add(stats.getSumAsString());
            line.add(stats.getAvgAsString());
            line.add(stats.getMinAsString());
            line.add(stats.getMaxAsString());
            if(isExtendedStats){
                ExtendedStats extendedStats = (ExtendedStats) aggregation;
                line.add(extendedStats.getSumOfSquaresAsString());
                line.add(extendedStats.getVarianceAsString());
                line.add(extendedStats.getStdDeviationAsString());
            }
        }
        else if( aggregation instanceof Percentiles){
            String[] percentileHeaders = new String[]{"1.0", "5.0", "25.0", "50.0", "75.0", "95.0", "99.0"};
            mergeHeadersWithPrefix(header, name, percentileHeaders);
            Percentiles percentiles = (Percentiles) aggregation;
            line.add(percentiles.percentileAsString(1.0));
            line.add(percentiles.percentileAsString(5.0));
            line.add(percentiles.percentileAsString(25.0));
            line.add(percentiles.percentileAsString(50.0));
            line.add(percentiles.percentileAsString(75));
            line.add(percentiles.percentileAsString(95.0));
            line.add(percentiles.percentileAsString(99.0));
        }
        else {
            throw new CsvExtractorException("unknown NumericMetricsAggregation.MultiValue:" + aggregation.getClass());
        }

    }
    else {
        throw new CsvExtractorException("unknown NumericMetricsAggregation" + aggregation.getClass());
    }
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:55,代码来源:CSVResultsExtractor.java


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