From 5c44db50bc913b2ab8637bc181e12f181157cc4f Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Thu, 5 Mar 2015 10:56:13 +0000 Subject: [PATCH] [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 --- .../bucket/datehistogram-aggregation.asciidoc | 14 +++++++------- .../bucket/daterange-aggregation.asciidoc | 14 +++++++------- .../bucket/geodistance-aggregation.asciidoc | 14 +++++++------- .../bucket/histogram-aggregation.asciidoc | 5 +++-- .../bucket/iprange-aggregation.asciidoc | 4 ++-- .../aggregations/bucket/range-aggregation.asciidoc | 8 ++++---- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/docs/java-api/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/java-api/aggregations/bucket/datehistogram-aggregation.asciidoc index cab70cf4f60..dd61767e512 100644 --- a/docs/java-api/aggregations/bucket/datehistogram-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/datehistogram-aggregation.asciidoc @@ -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); } diff --git a/docs/java-api/aggregations/bucket/daterange-aggregation.asciidoc b/docs/java-api/aggregations/bucket/daterange-aggregation.asciidoc index 54abb357470..b86bec68086 100644 --- a/docs/java-api/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/daterange-aggregation.asciidoc @@ -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); } diff --git a/docs/java-api/aggregations/bucket/geodistance-aggregation.asciidoc b/docs/java-api/aggregations/bucket/geodistance-aggregation.asciidoc index 9b8f776c03f..e3a9d95c0e3 100644 --- a/docs/java-api/aggregations/bucket/geodistance-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/geodistance-aggregation.asciidoc @@ -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); } diff --git a/docs/java-api/aggregations/bucket/histogram-aggregation.asciidoc b/docs/java-api/aggregations/bucket/histogram-aggregation.asciidoc index c4e5ec535e8..f5c8abe2e7e 100644 --- a/docs/java-api/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/histogram-aggregation.asciidoc @@ -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 } -------------------------------------------------- diff --git a/docs/java-api/aggregations/bucket/iprange-aggregation.asciidoc b/docs/java-api/aggregations/bucket/iprange-aggregation.asciidoc index c7bef4c8ed0..3cf301ffaee 100644 --- a/docs/java-api/aggregations/bucket/iprange-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/iprange-aggregation.asciidoc @@ -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 diff --git a/docs/java-api/aggregations/bucket/range-aggregation.asciidoc b/docs/java-api/aggregations/bucket/range-aggregation.asciidoc index 512c3d4772a..3b0f8174eae 100644 --- a/docs/java-api/aggregations/bucket/range-aggregation.asciidoc +++ b/docs/java-api/aggregations/bucket/range-aggregation.asciidoc @@ -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); }