當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。