|
@@ -16,7 +16,7 @@ AggregationBuilder aggregation =
|
|
|
AggregationBuilders
|
|
|
.dateHistogram("agg")
|
|
|
.field("dateOfBirth")
|
|
|
- .interval(DateHistogram.Interval.YEAR);
|
|
|
+ .interval(DateHistogramInterval.YEAR);
|
|
|
--------------------------------------------------
|
|
|
|
|
|
Or if you want to set an interval of 10 days:
|
|
@@ -27,7 +27,7 @@ AggregationBuilder aggregation =
|
|
|
AggregationBuilders
|
|
|
.dateHistogram("agg")
|
|
|
.field("dateOfBirth")
|
|
|
- .interval(DateHistogram.Interval.days(10));
|
|
|
+ .interval(DateHistogramInterval.days(10));
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
@@ -43,13 +43,13 @@ import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
|
|
[source,java]
|
|
|
--------------------------------------------------
|
|
|
// sr is here your SearchResponse object
|
|
|
-DateHistogram agg = sr.getAggregations().get("agg");
|
|
|
+Histogram agg = sr.getAggregations().get("agg");
|
|
|
|
|
|
// For each entry
|
|
|
-for (DateHistogram.Bucket entry : agg.getBuckets()) {
|
|
|
- String key = entry.getKey(); // Key
|
|
|
- DateTime keyAsDate = entry.getKeyAsDate(); // Key as date
|
|
|
- long docCount = entry.getDocCount(); // Doc count
|
|
|
+for (Histogram.Bucket entry : agg.getBuckets()) {
|
|
|
+ DateTime keyAsDate = (DateTime) entry.getKey(); // Key
|
|
|
+ String key = entry.getKeyAsString(); // Key as String
|
|
|
+ long docCount = entry.getDocCount(); // Doc count
|
|
|
|
|
|
logger.info("key [{}], date [{}], doc_count [{}]", key, keyAsDate.getYear(), docCount);
|
|
|
}
|