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


Java Range类代码示例

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


Range类属于org.elasticsearch.search.aggregations.bucket.range包,在下文中一共展示了Range类的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: testDateRange

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入依赖的package包/类
public void testDateRange() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .setQuery(QueryBuilders.matchAllQuery())
            .addAggregation(dateRange("range").field("date").addRange("r1", "2014-01-01", "2014-01-10")
                    .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0)))
            .execute().actionGet();

    assertSearchResponse(response);

    Range range = response.getAggregations().get("range");
    Histogram histo = range.getBuckets().get(0).getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:ShardReduceIT.java

示例9: testIpRange

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入依赖的package包/类
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/17700")
public void testIpRange() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .setQuery(QueryBuilders.matchAllQuery())
            .addAggregation(ipRange("range").field("ip").addRange("r1", "10.0.0.1", "10.0.0.10")
                    .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0)))
            .execute().actionGet();

    assertSearchResponse(response);

    Range range = response.getAggregations().get("range");
    Histogram histo = range.getBuckets().get(0).getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:ShardReduceIT.java

示例10: 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

示例11: testRangeAgg

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入依赖的package包/类
public void testRangeAgg() {
    SearchResponse response = client().prepareSearch("old_index", "new_index")
            .addAggregation(AggregationBuilders.ipRange("ip_range").field("ip_field")
                    .addMaskRange("127.0.0.1/16")
                    .addMaskRange("::1/64")).get();
    assertNoFailures(response);
    assertEquals(3, response.getHits().getTotalHits());
    Range range = response.getAggregations().get("ip_range");
    assertEquals(2, range.getBuckets().size());
    assertEquals("::1/64", range.getBuckets().get(0).getKeyAsString());
    assertEquals(3, range.getBuckets().get(0).getDocCount());
    assertEquals("127.0.0.1/16", range.getBuckets().get(1).getKeyAsString());
    assertEquals(2, range.getBuckets().get(1).getDocCount());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:IpFieldBwCompatIT.java

示例12: ElasticsearchFacetFieldCollector

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入依赖的package包/类
public ElasticsearchFacetFieldCollector(Aggregation facet) {
	if (facet instanceof Range) {
		initialize((Range)facet);
	}
	else {
		initialize((Terms)facet);
	}
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:9,代码来源:ElasticsearchFacetFieldCollector.java

示例13: 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

示例14: testSingleValueField

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入依赖的package包/类
public void testSingleValueField() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("date")
                    .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(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

示例15: 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


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