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


Java Range.Bucket方法代码示例

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


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

示例1: testSingleValuedField

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testSingleValuedField() {
    SearchResponse rsp = client().prepareSearch("idx").addAggregation(
            AggregationBuilders.ipRange("my_range")
                .field("ip")
                .addUnboundedTo("192.168.1.0")
                .addRange("192.168.1.0", "192.168.1.10")
                .addUnboundedFrom("192.168.1.10")).get();
    assertSearchResponse(rsp);
    Range range = rsp.getAggregations().get("my_range");
    assertEquals(3, range.getBuckets().size());

    Range.Bucket bucket1 = range.getBuckets().get(0);
    assertNull(bucket1.getFrom());
    assertEquals("192.168.1.0", bucket1.getTo());
    assertEquals(0, bucket1.getDocCount());

    Range.Bucket bucket2 = range.getBuckets().get(1);
    assertEquals("192.168.1.0", bucket2.getFrom());
    assertEquals("192.168.1.10", bucket2.getTo());
    assertEquals(1, bucket2.getDocCount());

    Range.Bucket bucket3 = range.getBuckets().get(2);
    assertEquals("192.168.1.10", bucket3.getFrom());
    assertNull(bucket3.getTo());
    assertEquals(2, bucket3.getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IpRangeIT.java

示例2: testMultiValuedField

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testMultiValuedField() {
    SearchResponse rsp = client().prepareSearch("idx").addAggregation(
            AggregationBuilders.ipRange("my_range")
                .field("ips")
                .addUnboundedTo("192.168.1.0")
                .addRange("192.168.1.0", "192.168.1.10")
                .addUnboundedFrom("192.168.1.10")).get();
    assertSearchResponse(rsp);
    Range range = rsp.getAggregations().get("my_range");
    assertEquals(3, range.getBuckets().size());

    Range.Bucket bucket1 = range.getBuckets().get(0);
    assertNull(bucket1.getFrom());
    assertEquals("192.168.1.0", bucket1.getTo());
    assertEquals(1, bucket1.getDocCount());

    Range.Bucket bucket2 = range.getBuckets().get(1);
    assertEquals("192.168.1.0", bucket2.getFrom());
    assertEquals("192.168.1.10", bucket2.getTo());
    assertEquals(1, bucket2.getDocCount());

    Range.Bucket bucket3 = range.getBuckets().get(2);
    assertEquals("192.168.1.10", bucket3.getFrom());
    assertNull(bucket3.getTo());
    assertEquals(2, bucket3.getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IpRangeIT.java

示例3: testIpMask

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testIpMask() {
    SearchResponse rsp = client().prepareSearch("idx").addAggregation(
            AggregationBuilders.ipRange("my_range")
                .field("ips")
                .addMaskRange("::/0")
                .addMaskRange("0.0.0.0/0")
                .addMaskRange("2001:db8::/64")).get();
    assertSearchResponse(rsp);
    Range range = rsp.getAggregations().get("my_range");
    assertEquals(3, range.getBuckets().size());

    Range.Bucket bucket1 = range.getBuckets().get(0);
    assertEquals("::/0", bucket1.getKey());
    assertEquals(3, bucket1.getDocCount());

    Range.Bucket bucket2 = range.getBuckets().get(1);
    assertEquals("0.0.0.0/0", bucket2.getKey());
    assertEquals(2, bucket2.getDocCount());

    Range.Bucket bucket3 = range.getBuckets().get(2);
    assertEquals("2001:db8::/64", bucket3.getKey());
    assertEquals(1, bucket3.getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:IpRangeIT.java

示例4: testPartiallyUnmapped

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testPartiallyUnmapped() {
    SearchResponse rsp = client().prepareSearch("idx", "idx_unmapped").addAggregation(
            AggregationBuilders.ipRange("my_range")
                .field("ip")
                .addUnboundedTo("192.168.1.0")
                .addRange("192.168.1.0", "192.168.1.10")
                .addUnboundedFrom("192.168.1.10")).get();
    assertSearchResponse(rsp);
    Range range = rsp.getAggregations().get("my_range");
    assertEquals(3, range.getBuckets().size());

    Range.Bucket bucket1 = range.getBuckets().get(0);
    assertNull(bucket1.getFrom());
    assertEquals("192.168.1.0", bucket1.getTo());
    assertEquals(0, bucket1.getDocCount());

    Range.Bucket bucket2 = range.getBuckets().get(1);
    assertEquals("192.168.1.0", bucket2.getFrom());
    assertEquals("192.168.1.10", bucket2.getTo());
    assertEquals(1, bucket2.getDocCount());

    Range.Bucket bucket3 = range.getBuckets().get(2);
    assertEquals("192.168.1.10", bucket3.getFrom());
    assertNull(bucket3.getTo());
    assertEquals(2, bucket3.getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IpRangeIT.java

示例5: testUnmapped

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testUnmapped() {
    SearchResponse rsp = client().prepareSearch("idx_unmapped").addAggregation(
            AggregationBuilders.ipRange("my_range")
                .field("ip")
                .addUnboundedTo("192.168.1.0")
                .addRange("192.168.1.0", "192.168.1.10")
                .addUnboundedFrom("192.168.1.10")).get();
    assertSearchResponse(rsp);
    Range range = rsp.getAggregations().get("my_range");
    assertEquals(3, range.getBuckets().size());

    Range.Bucket bucket1 = range.getBuckets().get(0);
    assertNull(bucket1.getFrom());
    assertEquals("192.168.1.0", bucket1.getTo());
    assertEquals(0, bucket1.getDocCount());

    Range.Bucket bucket2 = range.getBuckets().get(1);
    assertEquals("192.168.1.0", bucket2.getFrom());
    assertEquals("192.168.1.10", bucket2.getTo());
    assertEquals(0, bucket2.getDocCount());

    Range.Bucket bucket3 = range.getBuckets().get(2);
    assertEquals("192.168.1.10", bucket3.getFrom());
    assertNull(bucket3.getTo());
    assertEquals(0, bucket3.getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IpRangeIT.java

示例6: convertResult

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation aggregation, Aggregations aggs) {
    AggregationResults result = null;

    String name = aggregation.getName();
    if (aggs.get(name) instanceof Range) {
        Range ranges = aggs.get(name);
        List<Bucket> buckets = new ArrayList<>();
        for (Range.Bucket bucket : ranges.getBuckets()) {
            String label = bucket.getFrom() + " TO " + bucket.getTo();
            String key = bucket.getKeyAsString();
            Bucket b = new Bucket(key, bucket.getDocCount(), label);
            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,代码行数:25,代码来源:RangeAggregationConverter.java

示例7: convertResult

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
@Override
public AggregationResults convertResult(ResultsConverter resultsConverter, Aggregation aggregation, Aggregations aggs) {
    AggregationResults result = null;

    String name = aggregation.getName();
    if (aggs.get(name) instanceof Range) {
        Range ranges = (Range) aggs.get(name);
        List<Bucket> buckets = new ArrayList<>();
        for (Range.Bucket bucket : ranges.getBuckets()) {
            String label = bucket.getFrom() + " TO " + bucket.getTo();
            String key = bucket.getKey();
            Bucket b = new Bucket(key, bucket.getDocCount(), label);
            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,代码行数:25,代码来源:RangeAggregationConverter.java

示例8: testDateMath

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testDateMath() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("fieldname", "date");
    DateRangeAggregationBuilder rangeBuilder = dateRange("range");
    if (randomBoolean()) {
        rangeBuilder.field("date");
    } else {
        rangeBuilder.script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params));
    }
    SearchResponse response = client()
            .prepareSearch("idx")
            .addAggregation(
                    rangeBuilder.addUnboundedTo("a long time ago", "now-50y").addRange("recently", "now-50y", "now-1y")
                            .addUnboundedFrom("last year", "now-1y").timeZone(DateTimeZone.forID("EST"))).execute().actionGet();

    assertSearchResponse(response);

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

    // TODO: use diamond once JI-9019884 is fixed
    List<Range.Bucket> buckets = new ArrayList<>(range.getBuckets());

    Range.Bucket bucket = buckets.get(0);
    assertThat((String) bucket.getKey(), equalTo("a long time ago"));
    assertThat(bucket.getKeyAsString(), equalTo("a long time ago"));
    assertThat(bucket.getDocCount(), equalTo(0L));

    bucket = buckets.get(1);
    assertThat((String) bucket.getKey(), equalTo("recently"));
    assertThat(bucket.getKeyAsString(), equalTo("recently"));
    assertThat(bucket.getDocCount(), equalTo((long) numDocs));

    bucket = buckets.get(2);
    assertThat((String) bucket.getKey(), equalTo("last year"));
    assertThat(bucket.getKeyAsString(), equalTo("last year"));
    assertThat(bucket.getDocCount(), equalTo(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:DateRangeIT.java

示例9: initialize

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
protected void initialize(Range rangeFacet) {
	_facet = rangeFacet;

	for (Range.Bucket entry : rangeFacet.getBuckets()) {
		StringBundler sb = new StringBundler();

		sb.append("{");
		sb.append(entry.getFromAsString());
		sb.append("-");
		sb.append(entry.getToAsString());
		sb.append("}");

		_counts.put(sb.toString(), entry.getDocCount());
	}
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:16,代码来源:ElasticsearchFacetFieldCollector.java

示例10: testMultiValues

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testMultiValues() throws Exception {
    SearchResponse response = client().prepareSearch("idx-multi")
            .addAggregation(geoDistance("amsterdam_rings", new GeoPoint(52.3760, 4.894))
                    .field("location")
                    .unit(DistanceUnit.KILOMETERS)
                    .distanceType(org.elasticsearch.common.geo.GeoDistance.ARC)
                    .addUnboundedTo(500)
                    .addRange(500, 1000)
                    .addUnboundedFrom(1000))
            .execute().actionGet();

    assertSearchResponse(response);

    Range geoDist = response.getAggregations().get("amsterdam_rings");
    assertThat(geoDist, notNullValue());
    assertThat(geoDist.getName(), equalTo("amsterdam_rings"));
    List<? extends Bucket> buckets = geoDist.getBuckets();
    assertThat(geoDist.getBuckets().size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-500.0"));
    assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(0.0));
    assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(500.0));
    assertThat(bucket.getFromAsString(), equalTo("0.0"));
    assertThat(bucket.getToAsString(), equalTo("500.0"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("500.0-1000.0"));
    assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(500.0));
    assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(1000.0));
    assertThat(bucket.getFromAsString(), equalTo("500.0"));
    assertThat(bucket.getToAsString(), equalTo("1000.0"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("1000.0-*"));
    assertThat(((Number) bucket.getFrom()).doubleValue(), equalTo(1000.0));
    assertThat(((Number) bucket.getTo()).doubleValue(), equalTo(Double.POSITIVE_INFINITY));
    assertThat(bucket.getFromAsString(), equalTo("1000.0"));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:GeoDistanceIT.java

示例11: testSingleValueFieldWithStringDates

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testSingleValueFieldWithStringDates() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .addUnboundedTo("2012-02-15")
                    .addRange("2012-02-15", "2012-03-15")
                    .addUnboundedFrom("2012-03-15"))
            .execute().actionGet();

    assertSearchResponse(response);


    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-2012-02-15T00:00:00.000Z"));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-02-15T00:00:00.000Z-2012-03-15T00:00:00.000Z"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-03-15T00:00:00.000Z-*"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 4L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:46,代码来源:DateRangeIT.java

示例12: testSingleValueFieldWithStringDatesWithCustomFormat

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testSingleValueFieldWithStringDatesWithCustomFormat() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .format("yyyy-MM-dd")
                    .addUnboundedTo("2012-02-15")
                    .addRange("2012-02-15", "2012-03-15")
                    .addUnboundedFrom("2012-03-15"))
            .execute().actionGet();

    assertSearchResponse(response);


    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-2012-02-15"));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-02-15-2012-03-15"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15"));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-03-15-*"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15"));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 4L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:DateRangeIT.java

示例13: testSingleValueFieldWithDateMath

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testSingleValueFieldWithDateMath() throws Exception {
    DateTimeZone timezone = randomDateTimeZone();
    int timeZoneOffset = timezone.getOffset(date(2, 15));
    // if time zone is UTC (or equivalent), time zone suffix is "Z", else something like "+03:00", which we get with the "ZZ" format
    String feb15Suffix = timeZoneOffset == 0 ? "Z" : date(2,15, timezone).toString("ZZ");
    String mar15Suffix = timeZoneOffset == 0 ? "Z" : date(3,15, timezone).toString("ZZ");
    long expectedFirstBucketCount = timeZoneOffset < 0 ? 3L : 2L;

    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .addUnboundedTo("2012-02-15")
                    .addRange("2012-02-15", "2012-02-15||+1M")
                    .addUnboundedFrom("2012-02-15||+1M")
                    .timeZone(timezone))
            .execute().actionGet();

    assertSearchResponse(response);

    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(bucket.getDocCount(), equalTo(expectedFirstBucketCount));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix +
            "-2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15T00:00:00.000" + feb15Suffix));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix + "-*"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15, timezone).toDateTime(DateTimeZone.UTC)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15T00:00:00.000" + mar15Suffix));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 2L - expectedFirstBucketCount));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:DateRangeIT.java

示例14: testSingleValueFieldWithCustomKey

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testSingleValueFieldWithCustomKey() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .addUnboundedTo("r1", date(2, 15))
                    .addRange("r2", date(2, 15), date(3, 15))
                    .addUnboundedFrom("r3", date(3, 15)))
            .execute().actionGet();

    assertSearchResponse(response);


    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("r1"));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("r2"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("r3"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 4L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:46,代码来源:DateRangeIT.java

示例15: testMultiValuedField

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testMultiValuedField() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("dates")
                    .addUnboundedTo(date(2, 15))
                    .addRange(date(2, 15), date(3, 15))
                    .addUnboundedFrom(date(3, 15)))
            .execute().actionGet();

    assertSearchResponse(response);


    Range range = response.getAggregations().get("range");
    assertThat(range, notNullValue());
    assertThat(range.getName(), equalTo("range"));
    List<? extends Bucket> buckets = range.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Range.Bucket bucket = buckets.get(0);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("*-2012-02-15T00:00:00.000Z"));
    assertThat(((DateTime) bucket.getFrom()), nullValue());
    assertThat(((DateTime) bucket.getTo()), equalTo(date(2, 15)));
    assertThat(bucket.getFromAsString(), nullValue());
    assertThat(bucket.getToAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(2L));

    bucket = buckets.get(1);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-02-15T00:00:00.000Z-2012-03-15T00:00:00.000Z"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(2, 15)));
    assertThat(((DateTime) bucket.getTo()), equalTo(date(3, 15)));
    assertThat(bucket.getFromAsString(), equalTo("2012-02-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getDocCount(), equalTo(3L));

    bucket = buckets.get(2);
    assertThat(bucket, notNullValue());
    assertThat((String) bucket.getKey(), equalTo("2012-03-15T00:00:00.000Z-*"));
    assertThat(((DateTime) bucket.getFrom()), equalTo(date(3, 15)));
    assertThat(((DateTime) bucket.getTo()), nullValue());
    assertThat(bucket.getFromAsString(), equalTo("2012-03-15T00:00:00.000Z"));
    assertThat(bucket.getToAsString(), nullValue());
    assertThat(bucket.getDocCount(), equalTo(numDocs - 2L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:46,代码来源:DateRangeIT.java


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