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


Java Histogram类代码示例

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


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

示例1: testUnmapped

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    SearchResponse response = client()
            .prepareSearch("idx_unmapped")
            .addAggregation(
                    histogram("histo")
                            .field(FIELD_1_NAME)
                            .interval(interval)
                            .subAggregation(sum("field2Sum").field(FIELD_2_NAME))
                            .subAggregation(sum("field3Sum").field(FIELD_3_NAME))
                            .subAggregation(sum("field4Sum").field(FIELD_4_NAME))
                            .subAggregation(
                                    bucketScript("seriesArithmetic",
                                            new Script(ScriptType.INLINE,
                                                CustomScriptPlugin.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
                                            "field2Sum", "field3Sum", "field4Sum")))
                            .execute().actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    assertThat(deriv.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:BucketScriptIT.java

示例2: testEmptyAggregation

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
@Override
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
                    .subAggregation(randomCompression(percentileRanks("percentile_ranks").field("value"))
                            .values(10, 15)))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    Histogram.Bucket bucket = histo.getBuckets().get(1);
    assertThat(bucket, notNullValue());

    PercentileRanks reversePercentiles = bucket.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:TDigestPercentileRanksIT.java

示例3: countDomainByGatherTime

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
/**
 * 统计指定网站每天抓取数量
 *
 * @param domain 网站域名
 * @return
 */
public Map<Date, Long> countDomainByGatherTime(String domain) {
    AggregationBuilder aggregation =
            AggregationBuilders
                    .dateHistogram("agg")
                    .field("gatherTime")
                    .dateHistogramInterval(DateHistogramInterval.DAY).order(Histogram.Order.KEY_DESC);
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
            .setTypes(TYPE_NAME)
            .setQuery(QueryBuilders.matchQuery("domain", domain))
            .addAggregation(aggregation);
    SearchResponse response = searchRequestBuilder.execute().actionGet();
    Histogram agg = response.getAggregations().get("agg");
    Map<Date, Long> result = Maps.newHashMap();
    for (Histogram.Bucket entry : agg.getBuckets()) {
        DateTime key = (DateTime) entry.getKey();    // Key
        long docCount = entry.getDocCount();         // Doc count
        result.put(key.toDate(), docCount);
    }
    return result;
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:27,代码来源:CommonWebpageDAO.java

示例4: assertBucketContents

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
private void assertBucketContents(Histogram.Bucket actual, Double expectedCount, Double expectedValue) {
    // This is a gap bucket
    SimpleValue countDiff = actual.getAggregations().get("diff_counts");
    if (expectedCount == null) {
        assertThat("[_count] diff is not null", countDiff, nullValue());
    } else {
        assertThat("[_count] diff is null", countDiff, notNullValue());
        assertThat("[_count] diff does not match expected [" + countDiff.value() + " vs " + expectedCount + "]",
                countDiff.value(), closeTo(expectedCount, 0.1));
    }

    // This is a gap bucket
    SimpleValue valuesDiff = actual.getAggregations().get("diff_values");
    if (expectedValue == null) {
        assertThat("[value] diff is not null", valuesDiff, Matchers.nullValue());
    } else {
        assertThat("[value] diff is null", valuesDiff, notNullValue());
        assertThat("[value] diff does not match expected [" + valuesDiff.value() + " vs " + expectedValue + "]",
                valuesDiff.value(), closeTo(expectedValue, 0.1));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SerialDiffIT.java

示例5: testNoBuckets

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testNoBuckets() throws Exception {
    SearchResponse response = client()
            .prepareSearch("idx")
            .setQuery(rangeQuery(SINGLE_VALUED_FIELD_NAME).lt(minRandomValue))
            .addAggregation(
                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                            .subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))
                            .subAggregation(cumulativeSum("cumulative_sum", "sum"))).execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:CumulativeSumIT.java

示例6: testInlineScriptNoBucketsLeft

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testInlineScriptNoBucketsLeft() {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 > 10000)", Collections.emptyMap());

    SearchResponse response = client()
            .prepareSearch("idx")
            .addAggregation(
                    histogram("histo")
                            .field(FIELD_1_NAME)
                            .interval(interval)
                            .subAggregation(sum("field2Sum").field(FIELD_2_NAME))
                            .subAggregation(sum("field3Sum").field(FIELD_3_NAME))
                            .subAggregation(bucketSelector("bucketSelector", script, "field2Sum", "field3Sum")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:BucketSelectorIT.java

示例7: testUnmapped

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME,
        "Double.isNaN(_value0) ? false : (_value0 + _value1 > 100)", Collections.emptyMap());

    SearchResponse response = client().prepareSearch("idx_unmapped")
            .addAggregation(
                    histogram("histo")
                            .field(FIELD_1_NAME)
                            .interval(interval)
                            .subAggregation(sum("field2Sum").field(FIELD_2_NAME))
                            .subAggregation(sum("field3Sum").field(FIELD_3_NAME))
                            .subAggregation(bucketSelector("bucketSelector", script, "field2Sum", "field3Sum")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    assertThat(deriv.getBuckets().size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:BucketSelectorIT.java

示例8: testScriptMultiValued

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testScriptMultiValued() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(
                    histogram("histo")
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['l_values']", emptyMap()))
                            .interval(interval))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(numValuesBuckets));

    for (int i = 0; i < numValuesBuckets; ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        assertThat(bucket, notNullValue());
        assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) i * interval));
        assertThat(bucket.getDocCount(), equalTo(valuesCounts[i]));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:HistogramIT.java

示例9: testNoBucketsInHistogram

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testNoBucketsInHistogram() {

        SearchResponse response = client()
                .prepareSearch("idx").setTypes("type")
                .addAggregation(
                        histogram("histo").field("test").interval(interval)
                                .subAggregation(randomMetric("the_metric", VALUE_FIELD))
                                .subAggregation(movingAvg("movavg_counts", "the_metric")
                                        .window(windowSize)
                                        .modelBuilder(new SimpleModel.SimpleModelBuilder())
                                        .gapPolicy(gapPolicy))
                ).execute().actionGet();

        assertSearchResponse(response);

        Histogram histo = response.getAggregations().get("histo");
        assertThat(histo, notNullValue());
        assertThat(histo.getName(), equalTo("histo"));
        List<? extends Bucket> buckets = histo.getBuckets();
        assertThat(buckets.size(), equalTo(0));
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:MovAvgIT.java

示例10: testNoBucketsInHistogramWithPredict

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testNoBucketsInHistogramWithPredict() {
    int numPredictions = randomIntBetween(1,10);
    SearchResponse response = client()
            .prepareSearch("idx").setTypes("type")
            .addAggregation(
                    histogram("histo").field("test").interval(interval)
                            .subAggregation(randomMetric("the_metric", VALUE_FIELD))
                            .subAggregation(movingAvg("movavg_counts", "the_metric")
                                    .window(windowSize)
                                    .modelBuilder(new SimpleModel.SimpleModelBuilder())
                                    .gapPolicy(gapPolicy)
                                    .predict(numPredictions))
            ).execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:MovAvgIT.java

示例11: assertBucketContents

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
private void assertBucketContents(Histogram.Bucket actual, Double expectedCount, Double expectedValue) {
    // This is a gap bucket
    SimpleValue countMovAvg = actual.getAggregations().get("movavg_counts");
    if (expectedCount == null) {
        assertThat("[_count] movavg is not null", countMovAvg, nullValue());
    } else if (Double.isNaN(expectedCount)) {
        assertThat("[_count] movavg should be NaN, but is ["+countMovAvg.value()+"] instead", countMovAvg.value(), equalTo(Double.NaN));
    } else {
        assertThat("[_count] movavg is null", countMovAvg, notNullValue());
        assertTrue("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]",
                nearlyEqual(countMovAvg.value(), expectedCount, 0.1));
    }

    // This is a gap bucket
    SimpleValue valuesMovAvg = actual.getAggregations().get("movavg_values");
    if (expectedValue == null) {
        assertThat("[value] movavg is not null", valuesMovAvg, Matchers.nullValue());
    } else if (Double.isNaN(expectedValue)) {
        assertThat("[value] movavg should be NaN, but is ["+valuesMovAvg.value()+"] instead", valuesMovAvg.value(), equalTo(Double.NaN));
    } else {
        assertThat("[value] movavg is null", valuesMovAvg, notNullValue());
        assertTrue("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]",
                nearlyEqual(valuesMovAvg.value(), expectedValue, 0.1));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:MovAvgIT.java

示例12: testDateHistogram

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testDateHistogram() {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(
                    dateHistogram("my_histogram").field("date").dateHistogramInterval(DateHistogramInterval.YEAR).missing("2014-05-07"))
            .get();
    assertSearchResponse(response);
    Histogram histogram = response.getAggregations().get("my_histogram");
    assertEquals(2, histogram.getBuckets().size());
    assertEquals("2014-01-01T00:00:00.000Z", histogram.getBuckets().get(0).getKeyAsString());
    assertEquals(1, histogram.getBuckets().get(0).getDocCount());
    assertEquals("2015-01-01T00:00:00.000Z", histogram.getBuckets().get(1).getKeyAsString());
    assertEquals(1, histogram.getBuckets().get(1).getDocCount());

    response = client().prepareSearch("idx")
            .addAggregation(
                    dateHistogram("my_histogram").field("date").dateHistogramInterval(DateHistogramInterval.YEAR).missing("2015-05-07"))
            .get();
    assertSearchResponse(response);
    histogram = response.getAggregations().get("my_histogram");
    assertEquals(1, histogram.getBuckets().size());
    assertEquals("2015-01-01T00:00:00.000Z", histogram.getBuckets().get(0).getKeyAsString());
    assertEquals(2, histogram.getBuckets().get(0).getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MissingValueIT.java

示例13: testSingleValueWithPositiveOffset

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testSingleValueWithPositiveOffset() throws Exception {
    prepareIndex(date("2014-03-11T00:00:00+00:00"), 5, 1, 0);

    SearchResponse response = client().prepareSearch("idx2")
            .setQuery(matchAllQuery())
            .addAggregation(dateHistogram("date_histo")
                    .field("date")
                    .offset("2h")
                    .format(DATE_FORMAT)
                    .dateHistogramInterval(DateHistogramInterval.DAY))
            .execute().actionGet();

    assertThat(response.getHits().getTotalHits(), equalTo(5L));

    Histogram histo = response.getAggregations().get("date_histo");
    List<Histogram.Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(2));

    checkBucketFor(buckets.get(0), new DateTime(2014, 3, 10, 2, 0, DateTimeZone.UTC), 2L);
    checkBucketFor(buckets.get(1), new DateTime(2014, 3, 11, 2, 0, DateTimeZone.UTC), 3L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DateHistogramOffsetIT.java

示例14: testSingleValueWithNegativeOffset

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
public void testSingleValueWithNegativeOffset() throws Exception {
    prepareIndex(date("2014-03-11T00:00:00+00:00"), 5, -1, 0);

    SearchResponse response = client().prepareSearch("idx2")
            .setQuery(matchAllQuery())
            .addAggregation(dateHistogram("date_histo")
                    .field("date")
                    .offset("-2h")
                    .format(DATE_FORMAT)
                    .dateHistogramInterval(DateHistogramInterval.DAY))
            .execute().actionGet();

    assertThat(response.getHits().getTotalHits(), equalTo(5L));

    Histogram histo = response.getAggregations().get("date_histo");
    List<? extends Histogram.Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(2));

    checkBucketFor(buckets.get(0), new DateTime(2014, 3, 9, 22, 0, DateTimeZone.UTC), 2L);
    checkBucketFor(buckets.get(1), new DateTime(2014, 3, 10, 22, 0, DateTimeZone.UTC), 3L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DateHistogramOffsetIT.java

示例15: testMinDocCountOnHistogram

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入依赖的package包/类
private void testMinDocCountOnHistogram(Histogram.Order order) throws Exception {
    final int interval = randomIntBetween(1, 3);
    final SearchResponse allResponse = client().prepareSearch("idx").setTypes("type")
            .setSize(0)
            .setQuery(QUERY)
            .addAggregation(histogram("histo").field("d").interval(interval).order(order).minDocCount(0))
            .execute().actionGet();

    final Histogram allHisto = allResponse.getAggregations().get("histo");

    for (long minDocCount = 0; minDocCount < 50; ++minDocCount) {
        final SearchResponse response = client().prepareSearch("idx").setTypes("type")
                .setSize(0)
                .setQuery(QUERY)
                .addAggregation(histogram("histo").field("d").interval(interval).order(order).minDocCount(minDocCount))
                .execute().actionGet();
        assertSubset(allHisto, (Histogram) response.getAggregations().get("histo"), minDocCount);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MinDocCountIT.java


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