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


Java Stats类代码示例

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


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

示例1: toTimeseriesStatistics

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
private static TimeseriesStatistics toTimeseriesStatistics(Bucket bucket) {
    Stats stat = bucket.getAggregations().get("stats");

    long faultCount = bucket.getAggregations()
            .<Nested>get("nested").getAggregations()
            .<Filter>get("faults").getDocCount();

    TimeseriesStatistics s = new TimeseriesStatistics();
    s.setTimestamp(bucket.getKeyAsDate().getMillis());
    s.setAverage((long)stat.getAvg());
    s.setMin((long)stat.getMin());
    s.setMax((long)stat.getMax());
    s.setCount(stat.getCount());
    s.setFaultCount(faultCount);
    return s;
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:17,代码来源:AnalyticsServiceElasticsearch.java

示例2: convertResult

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
        aggregation, Aggregations aggs) {
    String name = aggregation.getName();
    AggregationResults result = null;
    if (aggs.get(name) instanceof Stats) {
        Stats stats = aggs.get(name);
        long count = stats.getCount();
        double sum = stats.getSum();
        double min = stats.getMin();
        double max = stats.getMax();
        double mean = stats.getAvg();
        com.scaleset.search.Stats resultStats = new com.scaleset.search.Stats(count, sum, min, max, mean);
        result = new AggregationResults(name, resultStats);
    }
    return result;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:18,代码来源:StatsAggregationConverter.java

示例3: convertResult

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
        aggregation, Aggregations aggs) {
    String name = aggregation.getName();
    AggregationResults result = null;
    if (aggs.get(name) instanceof Stats) {
        Stats stats = (Stats) (aggs.get(name));
        long count = stats.getCount();
        double sum = stats.getSum();
        double min = stats.getMin();
        double max = stats.getMax();
        double mean = stats.getAvg();
        com.scaleset.search.Stats resultStats = new com.scaleset.search.Stats(count, sum, min, max, mean);
        result = new AggregationResults(name, resultStats);
    }
    return result;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:18,代码来源:StatsAggregationConverter.java

示例4: testPartiallyUnmapped

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
public void testPartiallyUnmapped() {
    Stats s1 = client().prepareSearch("idx")
            .addAggregation(stats("stats").field("value")).get()
            .getAggregations().get("stats");
    Stats s2 = client().prepareSearch("idx", "idx_unmapped")
            .addAggregation(stats("stats").field("value")).get()
            .getAggregations().get("stats");
    assertEquals(s1.getAvg(), s2.getAvg(), 1e-10);
    assertEquals(s1.getCount(), s2.getCount());
    assertEquals(s1.getMin(), s2.getMin(), 0d);
    assertEquals(s1.getMax(), s2.getMax(), 0d);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:StatsIT.java

示例5: statsTest

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Test
public void statsTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
	Aggregations result = query(String.format("SELECT STATS(age) FROM %s/account", TEST_INDEX));
	Stats stats = result.get("STATS(age)");
	Assert.assertEquals(1000, stats.getCount());
	assertThat(stats.getSum(), equalTo(30171.0));
	assertThat(stats.getMin(), equalTo(20.0));
	assertThat(stats.getMax(), equalTo(40.0));
	assertThat(stats.getAvg(), equalTo(30.171));
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:11,代码来源:AggregationTest.java

示例6: statsTest

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Test
public void statsTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
	Aggregations result = query(String.format("SELECT STATS(age) FROM %s/account", TestsConstants.TEST_INDEX));
	Stats stats = result.get("STATS(age)");
	Assert.assertEquals(1000, stats.getCount());
	assertThat(stats.getSum(), equalTo(30171.0));
	assertThat(stats.getMin(), equalTo(20.0));
	assertThat(stats.getMax(), equalTo(40.0));
	assertThat(stats.getAvg(), equalTo(30.171));
}
 
开发者ID:selvakumarEsra,项目名称:es4sql,代码行数:11,代码来源:AggregationTest.java

示例7: calculateVoteStatsForUser

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
public VoteStats calculateVoteStatsForUser(String user, ReadablePeriod period) {
    final DateTime now = DateTime.now();
    DateTime past = now.minus(period);
    final SearchResponse stats = client.prepareSearch(ES_INDEX)
            .setTypes(ES_TYPE)
            .setQuery(QueryBuilders.filteredQuery(
                    QueryBuilders.nestedQuery("user", QueryBuilders.queryString("user.nickName: " + user)),
                    FilterBuilders.boolFilter().must(FilterBuilders.rangeFilter("timestamp").from(past).to(now))))
            .addAggregation(
                    AggregationBuilders.stats("voteStats")
                            .field("voteTotal")
            ).get();
    final Stats esStats = stats.getAggregations().get("voteStats");
    return new VoteStats().setCount(esStats.getCount()).setMax(esStats.getMax()).setMin(esStats.getMin()).setSum(esStats.getSum());
}
 
开发者ID:jalieven,项目名称:sarcasmotron,代码行数:16,代码来源:VoteCalculator.java

示例8: statsTest

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Test
public void statsTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
	Aggregations result = query(String.format("SELECT STATS(age) FROM %s/account", TEST_INDEX_ACCOUNT));
	Stats stats = result.get("STATS(age)");
	Assert.assertEquals(1000, stats.getCount());
	assertThat(stats.getSum(), equalTo(30171.0));
	assertThat(stats.getMin(), equalTo(20.0));
	assertThat(stats.getMax(), equalTo(40.0));
	assertThat(stats.getAvg(), equalTo(30.171));
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:11,代码来源:AggregationTest.java

示例9: convertResult

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
        aggregation, Aggregations aggs) {
    String name = aggregation.getName();
    AggregationResults result = null;
    if (aggs.get(name) instanceof GeoHashGrid) {
        GeoHashGrid grid = aggs.get(name);
        List<Bucket> buckets = new ArrayList<>();
        grid.getBuckets().stream().filter(bucket -> bucket.getDocCount() > 0).forEach(bucket -> {
            Bucket b = new Bucket(bucket.getKey(), bucket.getDocCount());
            Stats latStats = bucket.getAggregations().get("lat_stats");
            Stats lonStats = bucket.getAggregations().get("lon_stats");
            double minx = lonStats.getMin();
            double maxx = lonStats.getMax();
            double miny = latStats.getMin();
            double maxy = latStats.getMax();
            double cx = lonStats.getAvg();
            double cy = latStats.getAvg();
            Envelope bbox = new Envelope(minx, maxx, miny, maxy);
            b.put("bbox", bbox);
            b.put("centroid", new Coordinate(cx, cy));
            buckets.add(b);
            for (Aggregation subAgg : aggregation.getAggs().values()) {
                AggregationResults subResults = resultsConverter.convertResults(subAgg, bucket.getAggregations());
                if (subResults != null) {
                    b.getAggs().put(subAgg.getName(), subResults);
                }
            }

        });
        result = new AggregationResults(name, buckets);
    }
    return result;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:35,代码来源:GeoHashGridStatsAggregationConverter.java

示例10: convertResult

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation
        aggregation, Aggregations aggs) {
    String name = aggregation.getName();
    AggregationResults result = null;
    if (aggs.get(name) instanceof GeoHashGrid) {
        GeoHashGrid grid = (GeoHashGrid) (aggs.get(name));
        List<Bucket> buckets = new ArrayList<>();
        for (GeoHashGrid.Bucket bucket : grid.getBuckets()) {
            if (bucket.getDocCount() > 0) {
                Bucket b = new Bucket(bucket.getKey(), bucket.getDocCount());
                Stats latStats = bucket.getAggregations().get("lat_stats");
                Stats lonStats = bucket.getAggregations().get("lon_stats");
                double minx = lonStats.getMin();
                double maxx = lonStats.getMax();
                double miny = latStats.getMin();
                double maxy = latStats.getMax();
                double cx = lonStats.getAvg();
                double cy = latStats.getAvg();
                Envelope bbox = new Envelope(minx, maxx, miny, maxy);
                b.put("bbox", bbox);
                b.put("centroid", new Coordinate(cx, cy));
                buckets.add(b);
                for (Aggregation subAgg : aggregation.getAggs().values()) {
                    AggregationResults subResults = resultsConverter.convertResults(subAgg, bucket.getAggregations());
                    if (subResults != null) {
                        b.getAggs().put(subAgg.getName(), subResults);
                    }
                }

            }
        }
        result = new AggregationResults(name, buckets);
    }
    return result;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:37,代码来源:GeoHashGridStatsAggregationConverter.java

示例11: combineShortSessions

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
public void combineShortSessions(ESDriver es, String user, int timeThres) throws ElasticsearchException, IOException {

    BoolQueryBuilder filterSearch = new BoolQueryBuilder();
    filterSearch.must(QueryBuilders.termQuery("IP", user));

    String[] indexArr = new String[] { logIndex };
    String[] typeArr = new String[] { cleanupType };
    int docCount = es.getDocCount(indexArr, typeArr, filterSearch);

    if (docCount < 3) {
      deleteInvalid(es, user);
      return;
    }

    BoolQueryBuilder filterCheck = new BoolQueryBuilder();
    filterCheck.must(QueryBuilders.termQuery("IP", user)).must(QueryBuilders.termQuery("Referer", "-"));
    SearchResponse checkReferer = es.getClient().prepareSearch(logIndex).setTypes(this.cleanupType).setScroll(new TimeValue(60000)).setQuery(filterCheck).setSize(0).execute().actionGet();

    long numInvalid = checkReferer.getHits().getTotalHits();
    double invalidRate = numInvalid / docCount;

    if (invalidRate >= 0.8) {
      deleteInvalid(es, user);
      return;
    }

    StatsAggregationBuilder statsAgg = AggregationBuilders.stats("Stats").field("Time");
    SearchResponse srSession = es.getClient().prepareSearch(logIndex).setTypes(this.cleanupType).setScroll(new TimeValue(60000)).setQuery(filterSearch)
        .addAggregation(AggregationBuilders.terms("Sessions").field("SessionID").size(docCount).subAggregation(statsAgg)).execute().actionGet();

    Terms sessions = srSession.getAggregations().get("Sessions");

    List<Session> sessionList = new ArrayList<>();
    for (Terms.Bucket session : sessions.getBuckets()) {
      Stats agg = session.getAggregations().get("Stats");
      Session sess = new Session(props, es, agg.getMinAsString(), agg.getMaxAsString(), session.getKey().toString());
      sessionList.add(sess);
    }

    Collections.sort(sessionList);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String last = null;
    String lastnewID = null;
    String lastoldID = null;
    String current = null;
    for (Session s : sessionList) {
      current = s.getEndTime();
      if (last != null) {
        if (Seconds.secondsBetween(fmt.parseDateTime(last), fmt.parseDateTime(current)).getSeconds() < timeThres) {
          if (lastnewID == null) {
            s.setNewID(lastoldID);
          } else {
            s.setNewID(lastnewID);
          }

          QueryBuilder fs = QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("SessionID", s.getID()));

          SearchResponse scrollResp = es.getClient().prepareSearch(logIndex).setTypes(this.cleanupType).setScroll(new TimeValue(60000)).setQuery(fs).setSize(100).execute().actionGet();
          while (true) {
            for (SearchHit hit : scrollResp.getHits().getHits()) {
              if (lastnewID == null) {
                update(es, logIndex, this.cleanupType, hit.getId(), "SessionID", lastoldID);
              } else {
                update(es, logIndex, this.cleanupType, hit.getId(), "SessionID", lastnewID);
              }
            }

            scrollResp = es.getClient().prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
            if (scrollResp.getHits().getHits().length == 0) {
              break;
            }
          }
        }
        ;
      }
      lastoldID = s.getID();
      lastnewID = s.getNewID();
      last = current;
    }

  }
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:82,代码来源:SessionGenerator.java

示例12: handleNumericMetricAggregation

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

示例13: handleNumericMetricAggregation

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

示例14: doAddMetrics

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的package包/类
private void doAddMetrics(CommunicationSummaryStatistics css, Stats duration, long docCount) {
    css.setMinimumDuration((long)duration.getMin());
    css.setAverageDuration((long)duration.getAvg());
    css.setMaximumDuration((long)duration.getMax());
    css.setCount(docCount);
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:7,代码来源:AnalyticsServiceElasticsearch.java

示例15: handleNumericMetricAggregation

import org.elasticsearch.search.aggregations.metrics.stats.Stats; //导入依赖的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.stats.Stats类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。