[doc] fix outdated java api examples

* QueryBuilders.queryString is now QueryBuilders.queryStringQuery
* DateHistogram.Interval is now DateHistogramInterval
* Refactoring of buckets in aggs
* FilterBuilders has been replaced by QueryBuilders

Closes #9976.
This commit is contained in:
David Pilato 2015-06-03 17:08:32 +02:00
parent fbf83e3568
commit 65b1ce9900
12 changed files with 32 additions and 31 deletions

View File

@ -47,11 +47,11 @@ Histogram agg = sr.getAggregations().get("agg");
// For each entry // For each entry
for (Histogram.Bucket entry : agg.getBuckets()) { for (Histogram.Bucket entry : agg.getBuckets()) {
DateTime keyAsDate = (DateTime) entry.getKey(); // Key DateTime key = (DateTime) entry.getKey(); // Key
String key = entry.getKeyAsString(); // Key as String String keyAsString = entry.getKeyAsString(); // Key as String
long docCount = entry.getDocCount(); // Doc count long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], date [{}], doc_count [{}]", key, keyAsDate.getYear(), docCount); logger.info("key [{}], date [{}], doc_count [{}]", keyAsString, key.getYear(), docCount);
} }
-------------------------------------------------- --------------------------------------------------

View File

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

View File

@ -14,7 +14,7 @@ Here is an example on how to create the aggregation request:
-------------------------------------------------- --------------------------------------------------
AggregationBuilders AggregationBuilders
.filter("agg") .filter("agg")
.filter(FilterBuilders.termFilter("gender", "male")); .filter(QueryBuilders.termQuery("gender", "male"));
-------------------------------------------------- --------------------------------------------------

View File

@ -15,8 +15,8 @@ Here is an example on how to create the aggregation request:
AggregationBuilder aggregation = AggregationBuilder aggregation =
AggregationBuilders AggregationBuilders
.filters("agg") .filters("agg")
.filter("men", FilterBuilders.termFilter("gender", "male")) .filter("men", QueryBuilders.termQuery("gender", "male"))
.filter("women", FilterBuilders.termFilter("gender", "female")); .filter("women", QueryBuilders.termQuery("gender", "female"));
-------------------------------------------------- --------------------------------------------------
@ -36,7 +36,7 @@ Filters agg = sr.getAggregations().get("agg");
// For each entry // For each entry
for (Filters.Bucket entry : agg.getBuckets()) { for (Filters.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // bucket key String key = entry.getKeyAsString(); // bucket key
long docCount = entry.getDocCount(); // Doc count long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], doc_count [{}]", key, docCount); logger.info("key [{}], doc_count [{}]", key, docCount);
} }

View File

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

View File

@ -36,11 +36,11 @@ GeoHashGrid agg = sr.getAggregations().get("agg");
// For each entry // For each entry
for (GeoHashGrid.Bucket entry : agg.getBuckets()) { for (GeoHashGrid.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // key as String String keyAsString = entry.getKeyAsString(); // key as String
GeoPoint keyAsGeoPoint = entry.getKeyAsGeoPoint(); // key as geo point GeoPoint key = (GeoPoint) entry.getKey(); // key as geo point
long docCount = entry.getDocCount(); // Doc count long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], point {}, doc_count [{}]", key, keyAsGeoPoint, docCount); logger.info("key [{}], point {}, doc_count [{}]", keyAsString, key, docCount);
} }
-------------------------------------------------- --------------------------------------------------

View File

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

View File

@ -46,11 +46,11 @@ import org.elasticsearch.search.aggregations.bucket.range.Range;
[source,java] [source,java]
-------------------------------------------------- --------------------------------------------------
// sr is here your SearchResponse object // sr is here your SearchResponse object
IPv4Range agg = sr.getAggregations().get("agg"); Range agg = sr.getAggregations().get("agg");
// For each entry // For each entry
for (Range.Bucket entry : agg.getBuckets()) { for (Range.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // Ip range as key String key = entry.getKeyAsString(); // Ip range as key
String fromAsString = entry.getFromAsString(); // Ip bucket from as a String String fromAsString = entry.getFromAsString(); // Ip bucket from as a String
String toAsString = entry.getToAsString(); // Ip bucket to as a String String toAsString = entry.getToAsString(); // Ip bucket to as a String
long docCount = entry.getDocCount(); // Doc count long docCount = entry.getDocCount(); // Doc count

View File

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

View File

@ -47,7 +47,7 @@ SearchResponse sr = node.client().prepareSearch()
AggregationBuilders.terms("by_country").field("country") AggregationBuilders.terms("by_country").field("country")
.subAggregation(AggregationBuilders.dateHistogram("by_year") .subAggregation(AggregationBuilders.dateHistogram("by_year")
.field("dateOfBirth") .field("dateOfBirth")
.interval((DateHistogram.Interval.YEAR) .interval((DateHistogramInterval.YEAR)
.subAggregation(AggregationBuilders.avg("avg_children").field("children")) .subAggregation(AggregationBuilders.avg("avg_children").field("children"))
) )
) )

View File

@ -416,7 +416,7 @@ See {ref}/query-dsl-query-filter.html[Query Filter]
[source,java] [source,java]
-------------------------------------------------- --------------------------------------------------
FilterBuilder filter = queryFilter( FilterBuilder filter = queryFilter(
queryString("this AND that OR thus") <1> queryStringQuery("this AND that OR thus") <1>
); );
-------------------------------------------------- --------------------------------------------------
<1> query you want to wrap as a filter <1> query you want to wrap as a filter

View File

@ -87,7 +87,7 @@ documentation
[source,java] [source,java]
-------------------------------------------------- --------------------------------------------------
SearchRequestBuilder srb1 = node.client() SearchRequestBuilder srb1 = node.client()
.prepareSearch().setQuery(QueryBuilders.queryString("elasticsearch")).setSize(1); .prepareSearch().setQuery(QueryBuilders.queryStringQuery("elasticsearch")).setSize(1);
SearchRequestBuilder srb2 = node.client() SearchRequestBuilder srb2 = node.client()
.prepareSearch().setQuery(QueryBuilders.matchQuery("name", "kimchy")).setSize(1); .prepareSearch().setQuery(QueryBuilders.matchQuery("name", "kimchy")).setSize(1);
@ -120,7 +120,7 @@ SearchResponse sr = node.client().prepareSearch()
.addAggregation( .addAggregation(
AggregationBuilders.dateHistogram("agg2") AggregationBuilders.dateHistogram("agg2")
.field("birth") .field("birth")
.interval(DateHistogram.Interval.YEAR) .interval(DateHistogramInterval.YEAR)
) )
.execute().actionGet(); .execute().actionGet();