Merge pull request #11477 from dadoonet/doc/update-java-api-master

[doc] fix outdated java api examples

Some API have been changed in master. Master documentation should reflect be updated:

* 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-16 09:45:51 +02:00
commit 2bc033d786
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 (Histogram.Bucket entry : agg.getBuckets()) {
DateTime keyAsDate = (DateTime) entry.getKey(); // Key
String key = entry.getKeyAsString(); // Key as String
long docCount = entry.getDocCount(); // Doc count
DateTime key = (DateTime) entry.getKey(); // Key
String keyAsString = entry.getKeyAsString(); // Key as String
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 (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
String key = entry.getKeyAsString(); // 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

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

View File

@ -40,10 +40,10 @@ Range agg = sr.getAggregations().get("agg");
// For each entry
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
String key = entry.getKeyAsString(); // 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,11 +36,11 @@ GeoHashGrid agg = sr.getAggregations().get("agg");
// For each entry
for (GeoHashGrid.Bucket entry : agg.getBuckets()) {
String key = entry.getKey(); // key as String
GeoPoint keyAsGeoPoint = entry.getKeyAsGeoPoint(); // key as geo point
long docCount = entry.getDocCount(); // Doc count
String keyAsString = entry.getKeyAsString(); // key as String
GeoPoint key = (GeoPoint) entry.getKey(); // key as geo point
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 (Histogram.Bucket entry : agg.getBuckets()) {
Number key = (Number) entry.getKey(); // Key
String keyAsString = entry.getKeyAsString(); // Key As String
long docCount = entry.getDocCount(); // Doc count
Long key = (Long) entry.getKey(); // Key
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]
--------------------------------------------------
// sr is here your SearchResponse object
IPv4Range agg = sr.getAggregations().get("agg");
Range agg = sr.getAggregations().get("agg");
// For each entry
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 toAsString = entry.getToAsString(); // Ip bucket to as a String
long docCount = entry.getDocCount(); // Doc count

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
String key = entry.getKeyAsString(); // Range as key
Number from = (Number) entry.getFrom(); // Bucket from
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);
}

View File

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

View File

@ -416,7 +416,7 @@ See {ref}/query-dsl-query-filter.html[Query Filter]
[source,java]
--------------------------------------------------
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

View File

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