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


Java DateHistogramInterval类代码示例

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


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

示例1: calculateStats

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public List<DateHistogramValue> calculateStats(String sourceUrl) {
    BoolQueryBuilder filter = QueryBuilders.boolQuery()
            .must(QueryBuilders.rangeQuery("created").gte("now-1M"))
            .must(QueryBuilders.termQuery("source", sourceUrl));

    SearchResponse response = getConnection().getClient()
            .prepareSearch(getIndex())
            .setTypes(getType())
            .setSearchType(SearchType.DEFAULT)
            .setQuery(filter)
            .addAggregation(AggregationBuilders
                    .dateHistogram("urls_over_time")
                    .field("created")
                    .format("yyyy-MM-dd")
                    .dateHistogramInterval(DateHistogramInterval.DAY))
            .setSize(0)
            .setFetchSource(true)
            .setExplain(false)
            .execute()
            .actionGet();

    InternalDateHistogram hits = response.getAggregations().get("urls_over_time");
    return hits.getBuckets().stream()
            .map(b -> new DateHistogramValue(b.getKeyAsString(), b.getDocCount()))
            .collect(Collectors.toList());
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:27,代码来源:EsDocumentOperations.java

示例2: testDateHistogram

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

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

示例3: testSingleValueWithPositiveOffset

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

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

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

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

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

示例4: testSingleValueWithNegativeOffset

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

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

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

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

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

示例5: testSingleValuedFieldOrderedByKeyAsc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByKeyAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.KEY_ASC))
            .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(3));

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

示例6: testSingleValuedFieldOrderedByKeyDesc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByKeyDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .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(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,代码行数:22,代码来源:DateHistogramIT.java

示例7: testSingleValuedFieldOrderedByCountAsc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByCountAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .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(3));

    int i = 0;
    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,代码行数:22,代码来源:DateHistogramIT.java

示例8: testSingleValuedFieldOrderedByCountDesc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByCountDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.COUNT_DESC))
            .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,代码行数:22,代码来源:DateHistogramIT.java

示例9: testSingleValuedFieldOrderedBySubAggregationAsc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedBySubAggregationAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("sum", true))
                    .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 = 0;
    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

示例10: testSingleValuedFieldOrderedBySubAggregationDesc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的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

示例11: testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("stats", "sum", false))
                    .subAggregation(stats("stats").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

示例12: testIssue8209

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
public void testIssue8209() throws InterruptedException, ExecutionException {
    assertAcked(client().admin().indices().prepareCreate("test8209").addMapping("type", "d", "type=date").get());
    indexRandom(true,
            client().prepareIndex("test8209", "type").setSource("d", "2014-01-01T00:00:00Z"),
            client().prepareIndex("test8209", "type").setSource("d", "2014-04-01T00:00:00Z"),
            client().prepareIndex("test8209", "type").setSource("d", "2014-04-30T00:00:00Z"));
    ensureSearchable("test8209");
    SearchResponse response = client().prepareSearch("test8209")
            .addAggregation(dateHistogram("histo").field("d").dateHistogramInterval(DateHistogramInterval.MONTH).timeZone(DateTimeZone.forID("CET"))
                    .minDocCount(0))
            .execute().actionGet();
    assertSearchResponse(response);
    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
    assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("2014-01-01T00:00:00.000+01:00"));
    assertThat(histo.getBuckets().get(0).getDocCount(), equalTo(1L));
    assertThat(histo.getBuckets().get(1).getKeyAsString(), equalTo("2014-02-01T00:00:00.000+01:00"));
    assertThat(histo.getBuckets().get(1).getDocCount(), equalTo(0L));
    assertThat(histo.getBuckets().get(2).getKeyAsString(), equalTo("2014-03-01T00:00:00.000+01:00"));
    assertThat(histo.getBuckets().get(2).getDocCount(), equalTo(0L));
    assertThat(histo.getBuckets().get(3).getKeyAsString(), equalTo("2014-04-01T00:00:00.000+02:00"));
    assertThat(histo.getBuckets().get(3).getDocCount(), equalTo(2L));
    internalCluster().wipeIndices("test8209");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:DateHistogramIT.java

示例13: testDSTEndTransition

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
/**
 * When DST ends, local time turns back one hour, so between 2am and 4am wall time we should have four buckets:
 * "2015-10-25T02:00:00.000+02:00",
 * "2015-10-25T02:00:00.000+01:00",
 * "2015-10-25T03:00:00.000+01:00",
 * "2015-10-25T04:00:00.000+01:00".
 */
public void testDSTEndTransition() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .setQuery(new MatchNoneQueryBuilder())
            .addAggregation(dateHistogram("histo").field("date").timeZone(DateTimeZone.forID("Europe/Oslo"))
                    .dateHistogramInterval(DateHistogramInterval.HOUR).minDocCount(0).extendedBounds(
                            new ExtendedBounds("2015-10-25T02:00:00.000+02:00", "2015-10-25T04:00:00.000+01:00")))
            .execute().actionGet();

    Histogram histo = response.getAggregations().get("histo");
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(4));
    assertThat(((DateTime) buckets.get(1).getKey()).getMillis() - ((DateTime) buckets.get(0).getKey()).getMillis(), equalTo(3600000L));
    assertThat(((DateTime) buckets.get(2).getKey()).getMillis() - ((DateTime) buckets.get(1).getKey()).getMillis(), equalTo(3600000L));
    assertThat(((DateTime) buckets.get(3).getKey()).getMillis() - ((DateTime) buckets.get(2).getKey()).getMillis(), equalTo(3600000L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateHistogramIT.java

示例14: countDomainByGatherTime

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

示例15: dateHistogramQuery

import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static void dateHistogramQuery(Client client ) {
	SearchResponse res = null;
	
	AggregationBuilder agg =
	        AggregationBuilders
	                .dateHistogram("agg")
	                .field("publish_date")
	                .interval(DateHistogramInterval.YEAR)
	                .minDocCount(1);
	res = client.prepareSearch("search_test")
			.setTypes("article")
			.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
			.addAggregation(agg)
			.setFrom(0)
			.setSize(0)
			.execute().actionGet();
	System.out.println(res);
	
	// on shutdown
	client.close();
}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:23,代码来源:AggsQueryTest.java


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