Skip to content

Commit

Permalink
Update Java documentation for 5.0
Browse files Browse the repository at this point in the history
Some of the methods have been removed or deprecated.

Also related to #21825.

Backport of #21831 in 5.x branch.
  • Loading branch information
dadoonet committed Nov 30, 2016
1 parent 56faeb3 commit 32b05b9
Show file tree
Hide file tree
Showing 33 changed files with 189 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AggregationBuilder aggregation =
AggregationBuilders
.dateHistogram("agg")
.field("dateOfBirth")
.interval(DateHistogramInterval.YEAR);
.dateHistogramInterval(DateHistogramInterval.YEAR);
--------------------------------------------------

Or if you want to set an interval of 10 days:
Expand All @@ -27,7 +27,7 @@ AggregationBuilder aggregation =
AggregationBuilders
.dateHistogram("agg")
.field("dateOfBirth")
.interval(DateHistogramInterval.days(10));
.dateHistogramInterval(DateHistogramInterval.days(10));
--------------------------------------------------


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Here is an example on how to create the aggregation request:
--------------------------------------------------
AggregationBuilder aggregation =
AggregationBuilders
.filters("agg", new KeyedFilter("men", QueryBuilders.termQuery("gender", "male")),
new KeyedFilter("women", QueryBuilders.termQuery("gender", "female")));
.filters("agg",
new FiltersAggregator.KeyedFilter("men", QueryBuilders.termQuery("gender", "male")),
new FiltersAggregator.KeyedFilter("women", QueryBuilders.termQuery("gender", "female")));
--------------------------------------------------


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Histogram agg = sr.getAggregations().get("agg");
// For each entry
for (Histogram.Bucket entry : agg.getBuckets()) {
Long key = (Long) entry.getKey(); // Key
Number key = (Number) entry.getKey(); // Key
long docCount = entry.getDocCount(); // Doc count
logger.info("key [{}], doc_count [{}]", key, docCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here is an example on how to create the aggregation request:
--------------------------------------------------
AggregationBuilder aggregation =
AggregationBuilders
.nested("agg").path("resellers")
.nested("agg", "resellers")
.subAggregation(
AggregationBuilders
.terms("name").field("resellers.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
AvgAggregationBuilder aggregation =
AggregationBuilders
.avg("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
CardinalityAggregationBuilder aggregation =
AggregationBuilders
.cardinality("agg")
.field("tags");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
ExtendedStatsAggregationBuilder aggregation =
AggregationBuilders
.extendedStats("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here is an example on how to create the aggregation request:
[source,java]
--------------------------------------------------
GeoBoundsBuilder aggregation =
AggregationBuilders
GeoBoundsAggregationBuilder
.geoBounds("agg")
.field("address.location")
.wrapLongitude(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
MaxAggregationBuilder aggregation =
AggregationBuilders
.max("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
MinAggregationBuilder aggregation =
AggregationBuilders
.min("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
PercentilesAggregationBuilder aggregation =
AggregationBuilders
.percentiles("agg")
.field("height");
Expand All @@ -22,7 +22,7 @@ You can provide your own percentiles instead of using defaults:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
PercentilesAggregationBuilder aggregation =
AggregationBuilders
.percentiles("agg")
.field("height")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
PercentileRanksAggregationBuilder aggregation =
AggregationBuilders
.percentileRanks("agg")
.field("height")
.percentiles(1.24, 1.91, 2.22);
.values(1.24, 1.91, 2.22);
--------------------------------------------------


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
AggregationBuilders
.scriptedMetric("agg")
.initScript("_agg['heights'] = []")
.mapScript(new Script("if (doc['gender'].value == \"male\") " +
"{ _agg.heights.add(doc['height'].value) } " +
"else " +
"{ _agg.heights.add(-1 * doc['height'].value) }"));
ScriptedMetricAggregationBuilder aggregation = AggregationBuilders
.scriptedMetric("agg")
.initScript(new Script("_agg['heights'] = []"))
.mapScript(new Script("if (doc['gender'].value == \"male\") " +
"{ _agg.heights.add(doc['height'].value) } " +
"else " +
"{ _agg.heights.add(-1 * doc['height'].value) }"));
--------------------------------------------------

You can also specify a `combine` script which will be executed on each shard:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
ScriptedMetricAggregationBuilder aggregation =
AggregationBuilders
.scriptedMetric("agg")
.initScript(new Script("_agg['heights'] = []"))
Expand All @@ -55,7 +54,7 @@ You can also specify a `reduce` script which will be executed on the node which

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
ScriptedMetricAggregationBuilder aggregation =
AggregationBuilders
.scriptedMetric("agg")
.initScript(new Script("_agg['heights'] = []"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
StatsAggregationBuilder aggregation =
AggregationBuilders
.stats("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
SumAggregationBuilder aggregation =
AggregationBuilders
.sum("agg")
.field("height");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is an example on how to create the aggregation request:

[source,java]
--------------------------------------------------
MetricsAggregationBuilder aggregation =
ValueCountAggregationBuilder aggregation =
AggregationBuilders
.count("agg")
.field("height");
Expand Down
1 change: 1 addition & 0 deletions docs/java-api/query-dsl/function-score-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FilterFunctionBuilder[] functions = {
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
exponentialDecayFunction("age", 0L, 1L)) <3>
};
QueryBuilder qb = QueryBuilders.functionScoreQuery(functions);
--------------------------------------------------
<1> Add a first function based on a query
<2> And randomize the score based on a given seed
Expand Down
8 changes: 1 addition & 7 deletions docs/java-api/query-dsl/geo-distance-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ See {ref}/query-dsl-geo-distance-query.html[Geo Distance Query]
--------------------------------------------------
QueryBuilder qb = geoDistanceQuery("pin.location") <1>
.point(40, -70) <2>
.distance(200, DistanceUnit.KILOMETERS) <3>
.optimizeBbox("memory") <4>
.geoDistance(GeoDistance.ARC); <5>
.distance(200, DistanceUnit.KILOMETERS); <3>
--------------------------------------------------
<1> field
<2> center point
<3> distance from center point
<4> optimize bounding box: `memory`, `indexed` or `none`
<5> distance computation mode: `GeoDistance.SLOPPY_ARC` (default), `GeoDistance.ARC` (slightly more precise but
significantly slower) or `GeoDistance.PLANE` (faster, but inaccurate on long distances and close to the poles)

26 changes: 0 additions & 26 deletions docs/java-api/query-dsl/geo-distance-range-query.asciidoc

This file was deleted.

2 changes: 1 addition & 1 deletion docs/java-api/query-dsl/geo-polygon-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ See {ref}/query-dsl-geo-polygon-query.html[Geo Polygon Query]

[source,java]
--------------------------------------------------
List<GeoPoint> points = new ArrayList<GeoPoint>(); <1>
List<GeoPoint> points = new ArrayList<>(); <1>
points.add(new GeoPoint(40, -70));
points.add(new GeoPoint(30, -80));
points.add(new GeoPoint(20, -90));
Expand Down
7 changes: 0 additions & 7 deletions docs/java-api/query-dsl/geo-queries.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ The queries in this group are:
Finds document with geo-points within the specified distance of a central
point.

<<java-query-dsl-geo-distance-range-query,`geo_distance_range`>> query::

Like the `geo_point` query, but the range starts at a specified distance
from the central point.

<<java-query-dsl-geo-polygon-query,`geo_polygon`>> query::

Find documents with geo-points within the specified polygon.
Expand All @@ -36,6 +31,4 @@ include::geo-bounding-box-query.asciidoc[]

include::geo-distance-query.asciidoc[]

include::geo-distance-range-query.asciidoc[]

include::geo-polygon-query.asciidoc[]
35 changes: 18 additions & 17 deletions docs/java-api/query-dsl/geo-shape-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,32 @@ import org.elasticsearch.common.geo.builders.ShapeBuilder;

[source,java]
--------------------------------------------------
GeoShapeQueryBuilder qb = geoShapeQuery(
"pin.location", <1>
ShapeBuilder.newMultiPoint() <2>
.point(0, 0)
.point(0, 10)
.point(10, 10)
.point(10, 0)
.point(0, 0));
qb.relation(ShapeRelation.WITHIN); <3>
List<Coordinate> points = new ArrayList<>();
points.add(new Coordinate(0, 0));
points.add(new Coordinate(0, 10));
points.add(new Coordinate(10, 10));
points.add(new Coordinate(10, 0));
points.add(new Coordinate(0, 0));
QueryBuilder qb = geoShapeQuery(
"pin.location", <1>
ShapeBuilders.newMultiPoint(points) <2>
.relation(ShapeRelation.WITHIN); <3>
--------------------------------------------------
<1> field
<2> shape
<3> relation can be `ShapeRelation.WITHIN`, `ShapeRelation.INTERSECTS` or `ShapeRelation.DISJOINT`
<3> relation can be `ShapeRelation.CONTAINS`, `ShapeRelation.WITHIN`, `ShapeRelation.INTERSECTS` or `ShapeRelation.DISJOINT`

[source,java]
--------------------------------------------------
// Using pre-indexed shapes
GeoShapeQueryBuilder qb = geoShapeQuery(
"pin.location", <1>
"DEU", <2>
"countries"); <3>
qb.relation(ShapeRelation.WITHIN)) <4>
.indexedShapeIndex("shapes") <5>
.indexedShapePath("location"); <6>
QueryBuilder qb = geoShapeQuery(
"pin.location", <1>
"DEU", <2>
"countries") <3>
.relation(ShapeRelation.WITHIN)) <4>
.indexedShapeIndex("shapes") <5>
.indexedShapePath("location"); <6>
--------------------------------------------------
<1> field
<2> The ID of the document that containing the pre-indexed shape.
Expand Down
4 changes: 3 additions & 1 deletion docs/java-api/query-dsl/has-child-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ See {ref}/query-dsl-has-child-query.html[Has Child Query]
--------------------------------------------------
QueryBuilder qb = hasChildQuery(
"blog_tag", <1>
termQuery("tag","something") <2>
termQuery("tag","something"), <2>
ScoreMode.Avg <3>
);
--------------------------------------------------
<1> child type to query against
<2> query
<3> score mode can be `ScoreMode.Avg`, `ScoreMode.Max`, `ScoreMode.Min`, `ScoreMode.None` or `ScoreMode.Total`

4 changes: 3 additions & 1 deletion docs/java-api/query-dsl/has-parent-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ See {ref}/query-dsl-has-parent-query.html[Has Parent]
--------------------------------------------------
QueryBuilder qb = hasParentQuery(
"blog", <1>
termQuery("tag","something") <2>
termQuery("tag","something"), <2>
false <3>
);
--------------------------------------------------
<1> parent type to query against
<2> query
<3> whether the score from the parent hit should propogate to the child hit
8 changes: 4 additions & 4 deletions docs/java-api/query-dsl/nested-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ QueryBuilder qb = nestedQuery(
"obj1", <1>
boolQuery() <2>
.must(matchQuery("obj1.name", "blue"))
.must(rangeQuery("obj1.count").gt(5))
)
.scoreMode(ScoreMode.Avg); <3>
.must(rangeQuery("obj1.count").gt(5)),
ScoreMode.Avg <3>
);
--------------------------------------------------
<1> path to nested document
<2> your query. Any fields referenced inside the query must use the complete path (fully qualified).
<3> score mode could be `max`, `total`, `avg` (default) or `none`
<3> score mode could be `ScoreMode.Max`, `ScoreMode.Min`, `ScoreMode.Total`, `ScoreMode.Avg` or `ScoreMode.None`
8 changes: 4 additions & 4 deletions docs/java-api/query-dsl/script-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ You can use it then with:
--------------------------------------------------
QueryBuilder qb = scriptQuery(
new Script(
"myscript", <1>
ScriptType.FILE, <2>
"painless", <3>
ImmutableMap.of("param1", 5)) <4>
"myscript", <1>
ScriptType.FILE, <2>
"painless", <3>
Collections.singletonMap("param1", 5)) <4>
);
--------------------------------------------------
<1> Script name
Expand Down
2 changes: 1 addition & 1 deletion docs/java-api/query-dsl/span-containing-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ See {ref}/query-dsl-span-containing-query.html[Span Containing Query]
--------------------------------------------------
QueryBuilder qb = spanContainingQuery(
spanNearQuery(spanTermQuery("field1","bar"), 5) <1>
.clause(spanTermQuery("field1","baz"))
.addClause(spanTermQuery("field1","baz"))
.inOrder(true),
spanTermQuery("field1","foo")); <2>
--------------------------------------------------
Expand Down
Loading

0 comments on commit 32b05b9

Please sign in to comment.