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


Java Range.getBuckets方法代码示例

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


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

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

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

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

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

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

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

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

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

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

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

示例11: testMultiValuedFieldWithValueScript

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testMultiValuedFieldWithValueScript() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("fieldname", "dates");
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .field("dates")
                            .script(new Script(ScriptType.INLINE, "native", DateScriptMocks.PlusOneMonthScript.NAME, params))
                            .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(1L));

    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 - 1L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:46,代码来源:DateRangeIT.java

示例12: testScriptSingleValue

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testScriptSingleValue() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("fieldname", "date");
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateRange("range")
                    .script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params))
                    .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,代码行数:48,代码来源:DateRangeIT.java

示例13: testScriptMultiValued

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testScriptMultiValued() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("fieldname", "dates");
    SearchResponse response = client()
            .prepareSearch("idx")
            .addAggregation(
                    dateRange("range").script(new Script(ScriptType.INLINE, "native", DateScriptMocks.ExtractFieldScript.NAME, params))
                    .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

示例14: testUnmapped

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testUnmapped() throws Exception {
    client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();

    SearchResponse response = client().prepareSearch("idx_unmapped")
            .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(0L));

    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(0L));

    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(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:DateRangeIT.java

示例15: testUnmappedWithStringDates

import org.elasticsearch.search.aggregations.bucket.range.Range; //导入方法依赖的package包/类
public void testUnmappedWithStringDates() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped")
            .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(0L));

    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(0L));

    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(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:46,代码来源:DateRangeIT.java


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