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


Java Histogram.Bucket方法代码示例

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


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

示例1: testMultiValuedFieldOrderedByKeyDesc

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testMultiValuedFieldOrderedByKeyDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(histogram("histo").field(MULTI_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.KEY_DESC))
            .execute().actionGet();

    assertSearchResponse(response);


    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(numValuesBuckets));

    // TODO: use diamond once JI-9019884 is fixed
    List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
    for (int i = 0; i < numValuesBuckets; ++i) {
        Histogram.Bucket bucket = buckets.get(numValuesBuckets - i - 1);
        assertThat(bucket, notNullValue());
        assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) i * interval));
        assertThat(bucket.getDocCount(), equalTo(valuesCounts[i]));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:HistogramIT.java

示例2: testSingleValuedFieldOrderedBySubAggregationDesc

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testSingleValuedFieldOrderedBySubAggregationDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("sum", false))
                    .subAggregation(max("sum").field("value")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(3));

    int i = 2;
    for (Histogram.Bucket bucket : histo.getBuckets()) {
        assertThat(((DateTime) bucket.getKey()), equalTo(new DateTime(2012, i + 1, 1, 0, 0, DateTimeZone.UTC)));
        i--;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateHistogramIT.java

示例3: testEmptyAggregation

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
                    .subAggregation(dateHistogram("date_histo").field("value").interval(1)))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, Matchers.notNullValue());
    List<? extends Histogram.Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Histogram.Bucket bucket = buckets.get(1);
    assertThat(bucket, Matchers.notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("1.0"));

    Histogram dateHisto = bucket.getAggregations().get("date_histo");
    assertThat(dateHisto, Matchers.notNullValue());
    assertThat(dateHisto.getName(), equalTo("date_histo"));
    assertThat(dateHisto.getBuckets().isEmpty(), is(true));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DateHistogramIT.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 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

示例5: testsingleValuedFieldOrderedByKeyDesc

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testsingleValuedFieldOrderedByKeyDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.KEY_DESC))
            .execute().actionGet();

    assertSearchResponse(response);


    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));

    // TODO: use diamond once JI-9019884 is fixed
    List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
    for (int i = 0; i < numValueBuckets; ++i) {
        Histogram.Bucket bucket = buckets.get(numValueBuckets - i - 1);
        assertThat(bucket, notNullValue());
        assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) i * interval));
        assertThat(bucket.getDocCount(), equalTo(valueCounts[i]));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:HistogramIT.java

示例6: testPartiallyUnmapped

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
            .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).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(numValueBuckets));

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

示例7: testEmptyAggregation

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
@Override
public void testEmptyAggregation() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client()
            .prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                    histogram("histo")
                            .field("value")
                            .interval(1L)
                            .minDocCount(0)
                            .subAggregation(
                                    percentileRanks("percentile_ranks").field("value").method(PercentilesMethod.HDR)
                                    .numberOfSignificantValueDigits(sigDigits).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,代码行数:29,代码来源:HDRPercentileRanksIT.java

示例8: testInlineScriptSingleVariable

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

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

    assertSearchResponse(response);

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

    for (int i = 0; i < buckets.size(); ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        Sum field2Sum = bucket.getAggregations().get("field2Sum");
        assertThat(field2Sum, notNullValue());
        double field2SumValue = field2Sum.getValue();
        assertThat(field2SumValue, greaterThan(100.0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:BucketSelectorIT.java

示例9: testSingleValuedFieldOrderedByCountAsc

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testSingleValuedFieldOrderedByCountAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.COUNT_ASC))
            .execute().actionGet();

    assertSearchResponse(response);


    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));

    LongHashSet buckets = new LongHashSet();
    // TODO: use diamond once JI-9019884 is fixed
    List<Histogram.Bucket> histoBuckets = new ArrayList<>(histo.getBuckets());
    long previousCount = Long.MIN_VALUE;
    for (int i = 0; i < numValueBuckets; ++i) {
        Histogram.Bucket bucket = histoBuckets.get(i);
        assertThat(bucket, notNullValue());
        long key = ((Number) bucket.getKey()).longValue();
        assertEquals(0, key % interval);
        assertTrue(buckets.add(key));
        assertThat(bucket.getDocCount(), equalTo(valueCounts[(int) (key / interval)]));
        assertThat(bucket.getDocCount(), greaterThanOrEqualTo(previousCount));
        previousCount = bucket.getDocCount();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:HistogramIT.java

示例10: testSingleValuedField_normalised

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
/**
 * test first and second derivative on the sing
 */
public void testSingleValuedField_normalised() {
    SearchResponse response = client()
            .prepareSearch("idx")
            .addAggregation(
                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).minDocCount(0)
                            .subAggregation(derivative("deriv", "_count").unit("1ms"))
                            .subAggregation(derivative("2nd_deriv", "deriv").unit("10ms"))).execute().actionGet();

    assertSearchResponse(response);

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

    for (int i = 0; i < numValueBuckets; ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        checkBucketKeyAndDocCount("InternalBucket " + i, bucket, i * interval, valueCounts[i]);
        Derivative docCountDeriv = bucket.getAggregations().get("deriv");
        if (i > 0) {
            assertThat(docCountDeriv, notNullValue());
            assertThat(docCountDeriv.value(), closeTo((firstDerivValueCounts[i - 1]), 0.00001));
            assertThat(docCountDeriv.normalizedValue(), closeTo((double) (firstDerivValueCounts[i - 1]) / 5, 0.00001));
        } else {
            assertThat(docCountDeriv, nullValue());
        }
        Derivative docCount2ndDeriv = bucket.getAggregations().get("2nd_deriv");
        if (i > 1) {
            assertThat(docCount2ndDeriv, notNullValue());
            assertThat(docCount2ndDeriv.value(), closeTo((secondDerivValueCounts[i - 2]), 0.00001));
            assertThat(docCount2ndDeriv.normalizedValue(), closeTo((double) (secondDerivValueCounts[i - 2]) * 2, 0.00001));
        } else {
            assertThat(docCount2ndDeriv, nullValue());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:DerivativeIT.java

示例11: testPartiallyUnmapped

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client()
            .prepareSearch("idx", "idx_unmapped")
            .addAggregation(
                    histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval)
                            .subAggregation(derivative("deriv", "_count"))).execute().actionGet();

    assertSearchResponse(response);

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

    for (int i = 0; i < numValueBuckets; ++i) {
        Histogram.Bucket bucket = buckets.get(i);
        checkBucketKeyAndDocCount("InternalBucket " + i, bucket, i * interval, valueCounts[i]);
        SimpleValue docCountDeriv = bucket.getAggregations().get("deriv");
        if (i > 0) {
            assertThat(docCountDeriv, notNullValue());
            assertThat(docCountDeriv.value(), equalTo((double) firstDerivValueCounts[i - 1]));
        } else {
            assertThat(docCountDeriv, nullValue());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:DerivativeIT.java

示例12: testPartiallyUnmappedWithExtendedBounds

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testPartiallyUnmappedWithExtendedBounds() throws Exception {
    SearchResponse response = client()
            .prepareSearch("idx", "idx_unmapped")
            .addAggregation(
                    histogram("histo")
                            .field(SINGLE_VALUED_FIELD_NAME)
                            .interval(interval)
                            .extendedBounds(-1 * 2 * interval, valueCounts.length * interval))
            .get();

    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(numValueBuckets + 3));

    Histogram.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) -1 * 2 * interval));
    assertThat(bucket.getDocCount(), equalTo(0L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat(((Number) bucket.getKey()).longValue(), equalTo((long) -1 * interval));
    assertThat(bucket.getDocCount(), equalTo(0L));

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

示例13: testSingleValueWithTimeZone

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testSingleValueWithTimeZone() throws Exception {
    prepareCreate("idx2").addMapping("type", "date", "type=date").execute().actionGet();
    IndexRequestBuilder[] reqs = new IndexRequestBuilder[5];
    DateTime date = date("2014-03-11T00:00:00+00:00");
    for (int i = 0; i < reqs.length; i++) {
        reqs[i] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", date).endObject());
        date = date.plusHours(1);
    }
    indexRandom(true, reqs);

    SearchResponse response = client().prepareSearch("idx2")
            .setQuery(matchAllQuery())
            .addAggregation(dateHistogram("date_histo")
                    .field("date")
                    .timeZone(DateTimeZone.forID("-02:00"))
                    .dateHistogramInterval(DateHistogramInterval.DAY)
                    .format("yyyy-MM-dd:HH-mm-ssZZ"))
            .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));

    Histogram.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("2014-03-10:00-00-00-02:00"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("2014-03-11:00-00-00-02:00"));
    assertThat(bucket.getDocCount(), equalTo(3L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:DateHistogramIT.java

示例14: countDomainByGatherTime

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
/**
 * 统计指定网站每天抓取数量
 * @param domain
 * @return
 */
public Map<Date, Long> countDomainByGatherTime(String domain) {
	SearchResponse response = search().setQuery(QueryBuilders.matchQuery("domain", domain))
			.addAggregation(AggregationBuilders.dateHistogram("agg").field("gatherTime")
					.dateHistogramInterval(DateHistogramInterval.DAY).order(Histogram.Order.KEY_DESC)).get();
	Map<Date, Long> count = new LinkedHashMap<>();
	for(Histogram.Bucket bucket:((Histogram)(Histogram)response.getAggregations().get("agg")).getBuckets()) 
		count.put(((DateTime)bucket.getKey()).toDate(), bucket.getDocCount());
	return count;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:15,代码来源:WebpageDAO.java

示例15: testSingleValued_timeZone_epoch

import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; //导入方法依赖的package包/类
public void testSingleValued_timeZone_epoch() throws Exception {
    String format = randomBoolean() ? "epoch_millis" : "epoch_second";
    int millisDivider = format.equals("epoch_millis") ? 1 : 1000;
    if (randomBoolean()) {
        format = format + "||date_optional_time";
    }
    DateTimeZone tz = DateTimeZone.forID("+01:00");
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo").field("date")
                    .dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(1)
                    .timeZone(tz).format(format))
            .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(6));

    List<DateTime> expectedKeys = new ArrayList<>();
    expectedKeys.add(new DateTime(2012, 1, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 2, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 2, 14, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 1, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 14, 23, 0, DateTimeZone.UTC));
    expectedKeys.add(new DateTime(2012, 3, 22, 23, 0, DateTimeZone.UTC));


    Iterator<DateTime> keyIterator = expectedKeys.iterator();
    for (Histogram.Bucket bucket : buckets) {
        assertThat(bucket, notNullValue());
        DateTime expectedKey = keyIterator.next();
        assertThat(bucket.getKeyAsString(), equalTo(Long.toString(expectedKey.getMillis() / millisDivider)));
        assertThat(((DateTime) bucket.getKey()), equalTo(expectedKey));
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:DateHistogramIT.java


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