|
@@ -1,7 +1,7 @@
|
|
|
[[search-aggregations-metrics-geocentroid-aggregation]]
|
|
|
=== Geo Centroid Aggregation
|
|
|
|
|
|
-A metric aggregation that computes the weighted https://en.wikipedia.org/wiki/Centroid[centroid] from all coordinate values for a <<geo-point>> field.
|
|
|
+A metric aggregation that computes the weighted https://en.wikipedia.org/wiki/Centroid[centroid] from all coordinate values for geo fields.
|
|
|
|
|
|
Example:
|
|
|
|
|
@@ -144,6 +144,87 @@ The response for the above aggregation:
|
|
|
--------------------------------------------------
|
|
|
// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
|
|
|
|
|
|
+
|
|
|
+[discrete]
|
|
|
+[role="xpack"]
|
|
|
+==== Geo Centroid Aggregation on `geo_shape` fields
|
|
|
+
|
|
|
+The centroid metric for geo-shapes is more nuanced than for points. The centroid of a specific aggregation bucket
|
|
|
+containing shapes is the centroid of the highest-dimensionality shape type in the bucket. For example, if a bucket contains
|
|
|
+shapes comprising of polygons and lines, then the lines do not contribute to the centroid metric. Each type of shape's
|
|
|
+centroid is calculated differently. Envelopes and circles ingested via the <<ingest-circle-processor>> are treated
|
|
|
+as polygons.
|
|
|
+
|
|
|
+|===
|
|
|
+|Geometry Type | Centroid Calculation
|
|
|
+
|
|
|
+|[Multi]Point
|
|
|
+|equally weighted average of all the coordinates
|
|
|
+
|
|
|
+|[Multi]LineString
|
|
|
+|a weighted average of all the centroids of each segment, where the weight of each segment is its length in degrees
|
|
|
+
|
|
|
+|[Multi]Polygon
|
|
|
+|a weighted average of all the centroids of all the triangles of a polygon where the triangles are formed by every two consecutive vertices and the starting-point.
|
|
|
+ holes have negative weights. weights represent the area of the triangle in deg^2 calculated
|
|
|
+
|
|
|
+|GeometryCollection
|
|
|
+|The centroid of all the underlying geometries with the highest dimension. If Polygons and Lines and/or Points, then lines and/or points are ignored.
|
|
|
+ If Lines and Points, then points are ignored
|
|
|
+|===
|
|
|
+
|
|
|
+Example:
|
|
|
+
|
|
|
+[source,console]
|
|
|
+--------------------------------------------------
|
|
|
+PUT /places
|
|
|
+{
|
|
|
+ "mappings": {
|
|
|
+ "properties": {
|
|
|
+ "geometry": {
|
|
|
+ "type": "geo_shape"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+POST /places/_bulk?refresh
|
|
|
+{"index":{"_id":1}}
|
|
|
+{"name": "NEMO Science Museum", "geometry": "POINT(4.912350 52.374081)" }
|
|
|
+{"index":{"_id":2}}
|
|
|
+{"name": "Sportpark De Weeren", "geometry": { "type": "Polygon", "coordinates": [ [ [ 4.965305328369141, 52.39347642069457 ], [ 4.966979026794433, 52.391721758934835 ], [ 4.969425201416015, 52.39238958618537 ], [ 4.967944622039794, 52.39420969150824 ], [ 4.965305328369141, 52.39347642069457 ] ] ] } }
|
|
|
+
|
|
|
+POST /places/_search?size=0
|
|
|
+{
|
|
|
+ "aggs" : {
|
|
|
+ "centroid" : {
|
|
|
+ "geo_centroid" : {
|
|
|
+ "field" : "geometry"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+--------------------------------------------------
|
|
|
+// TEST
|
|
|
+
|
|
|
+[source,console-result]
|
|
|
+--------------------------------------------------
|
|
|
+{
|
|
|
+ ...
|
|
|
+ "aggregations": {
|
|
|
+ "centroid": {
|
|
|
+ "location": {
|
|
|
+ "lat": 52.39296147599816,
|
|
|
+ "lon": 4.967404240742326
|
|
|
+ },
|
|
|
+ "count": 2
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+--------------------------------------------------
|
|
|
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
|
|
|
+
|
|
|
+
|
|
|
[WARNING]
|
|
|
.Using `geo_centroid` as a sub-aggregation of `geohash_grid`
|
|
|
====
|
|
@@ -152,8 +233,8 @@ aggregation places documents, not individual geo-points, into buckets. If a
|
|
|
document's `geo_point` field contains <<array,multiple values>>, the document
|
|
|
could be assigned to multiple buckets, even if one or more of its geo-points are
|
|
|
outside the bucket boundaries.
|
|
|
-
|
|
|
+
|
|
|
If a `geocentroid` sub-aggregation is also used, each centroid is calculated
|
|
|
using all geo-points in a bucket, including those outside the bucket boundaries.
|
|
|
This can result in centroids outside of bucket boundaries.
|
|
|
-====
|
|
|
+====
|