[DOCS] update JAVA API with aggregation changes

The Histogram and Range APIs for the aggregations changed so that there was a common interface between he types of Range/Histogram. This PR reflects that change in the Java API docs

Contributes to #9976
This commit is contained in:
Colin Goodheart-Smithe 2015-03-05 10:56:13 +00:00
parent 8935959cbf
commit 5c44db50bc
6 changed files with 30 additions and 29 deletions

View File

@ -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);
}

View File

@ -29,20 +29,20 @@ Import Aggregation definition classes:
[source,java]
--------------------------------------------------
import org.elasticsearch.search.aggregations.bucket.range.date.DateRange;
import org.elasticsearch.search.aggregations.bucket.range.Range;
--------------------------------------------------
[source,java]
--------------------------------------------------
// sr is here your SearchResponse object
DateRange agg = sr.getAggregations().get("agg");
Range agg = sr.getAggregations().get("agg");
// For each entry
for (DateRange.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Date range as key
DateTime fromAsDate = entry.getFromAsDate(); // Date bucket from as a Date
DateTime toAsDate = entry.getToAsDate(); // Date bucket to as a Date
long docCount = entry.getDocCount(); // Doc count
for (Range.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Date range as key
DateTime fromAsDate = (DateTime) entry.getFrom(); // Date bucket from as a Date
DateTime toAsDate = (DateTime) entry.getTo(); // Date bucket to as a Date
long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], from [{}], to [{}], doc_count [{}]", key, fromAsDate, toAsDate, docCount);
}

View File

@ -30,20 +30,20 @@ Import Aggregation definition classes:
[source,java]
--------------------------------------------------
import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistance;
import org.elasticsearch.search.aggregations.bucket.range.Range;
--------------------------------------------------
[source,java]
--------------------------------------------------
// sr is here your SearchResponse object
GeoDistance agg = sr.getAggregations().get("agg");
Range agg = sr.getAggregations().get("agg");
// For each entry
for (GeoDistance.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // key as String
Number from = entry.getFrom(); // bucket from value
Number to = entry.getTo(); // bucket to value
long docCount = entry.getDocCount(); // Doc count
for (Range.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // key as String
Number from = (Number) entry.getFrom(); // bucket from value
Number to = (Number) entry.getTo(); // bucket to value
long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], from [{}], to [{}], doc_count [{}]", key, from, to, docCount);
}

View File

@ -36,7 +36,8 @@ Histogram agg = sr.getAggregations().get("agg");
// For each entry
for (Histogram.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Key
long docCount = entry.getDocCount(); // Doc count
Number key = (Number) entry.getKey(); // Key
String keyAsString = entry.getKeyAsString(); // Key As String
long docCount = entry.getDocCount(); // Doc count
}
--------------------------------------------------

View File

@ -40,7 +40,7 @@ Import Aggregation definition classes:
[source,java]
--------------------------------------------------
import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4Range;
import org.elasticsearch.search.aggregations.bucket.range.Range;
--------------------------------------------------
[source,java]
@ -49,7 +49,7 @@ import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4Range;
IPv4Range agg = sr.getAggregations().get("agg");
// For each entry
for (IPv4Range.Bucket entry : agg.getBuckets()) {
for (Range.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Ip range as key
String fromAsString = entry.getFromAsString(); // Ip bucket from as a String
String toAsString = entry.getToAsString(); // Ip bucket to as a String

View File

@ -38,10 +38,10 @@ Range agg = sr.getAggregations().get("agg");
// For each entry
for (Range.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Range as key
Number from = entry.getFrom(); // Bucket from
Number to = entry.getTo(); // Bucket to
long docCount = entry.getDocCount(); // Doc count
String key = entry.getKey(); // Range as key
Number from = (Number) entry.getFrom(); // Bucket from
Number to = (Number) entry.getTo(); // Bucket to
long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], from [{}], to [{}], doc_count [{}]", key, from, to, docCount);
}