|
@@ -3,15 +3,39 @@
|
|
|
|
|
|
A metric aggregation that computes the weighted centroid from all coordinate values for a <<geo-point>> field.
|
|
|
|
|
|
-
|
|
|
Example:
|
|
|
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+PUT /museums
|
|
|
+{
|
|
|
+ "mappings": {
|
|
|
+ "doc": {
|
|
|
+ "properties": {
|
|
|
+ "location": {
|
|
|
+ "type": "geo_point"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+POST /museums/doc/_bulk?refresh
|
|
|
+{"index":{"_id":1}}
|
|
|
+{"location": "52.374081,4.912350", "city": "Amsterdam", "name": "NEMO Science Museum"}
|
|
|
+{"index":{"_id":2}}
|
|
|
+{"location": "52.369219,4.901618", "city": "Amsterdam", "name": "Museum Het Rembrandthuis"}
|
|
|
+{"index":{"_id":3}}
|
|
|
+{"location": "52.371667,4.914722", "city": "Amsterdam", "name": "Nederlands Scheepvaartmuseum"}
|
|
|
+{"index":{"_id":4}}
|
|
|
+{"location": "51.222900,4.405200", "city": "Antwerp", "name": "Letterenhuis"}
|
|
|
+{"index":{"_id":5}}
|
|
|
+{"location": "48.861111,2.336389", "city": "Paris", "name": "Musée du Louvre"}
|
|
|
+{"index":{"_id":6}}
|
|
|
+{"location": "48.860000,2.327000", "city": "Paris", "name": "Musée d'Orsay"}
|
|
|
+
|
|
|
+POST /museums/_search?size=0
|
|
|
{
|
|
|
- "query" : {
|
|
|
- "match" : { "crime" : "burglary" }
|
|
|
- },
|
|
|
"aggs" : {
|
|
|
"centroid" : {
|
|
|
"geo_centroid" : {
|
|
@@ -21,6 +45,7 @@ Example:
|
|
|
}
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
|
|
|
<1> The `geo_centroid` aggregation specifies the field to use for computing the centroid. (NOTE: field must be a <<geo-point>> type)
|
|
|
|
|
@@ -32,18 +57,17 @@ The response for the above aggregation:
|
|
|
--------------------------------------------------
|
|
|
{
|
|
|
...
|
|
|
-
|
|
|
"aggregations": {
|
|
|
"centroid": {
|
|
|
"location": {
|
|
|
- "lat": 80.45,
|
|
|
- "lon": -160.22
|
|
|
+ "lat": 51.009829603135586,
|
|
|
+ "lon": 3.966213036328554
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
-
|
|
|
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
|
|
|
|
|
|
The `geo_centroid` aggregation is more interesting when combined as a sub-aggregation to other bucket aggregations.
|
|
|
|
|
@@ -51,13 +75,11 @@ Example:
|
|
|
|
|
|
[source,js]
|
|
|
--------------------------------------------------
|
|
|
+POST /museums/_search?size=0
|
|
|
{
|
|
|
- "query" : {
|
|
|
- "match" : { "crime" : "burglary" }
|
|
|
- },
|
|
|
"aggs" : {
|
|
|
- "towns" : {
|
|
|
- "terms" : { "field" : "town" },
|
|
|
+ "cities" : {
|
|
|
+ "terms" : { "field" : "city.keyword" },
|
|
|
"aggs" : {
|
|
|
"centroid" : {
|
|
|
"geo_centroid" : { "field" : "location" }
|
|
@@ -67,9 +89,12 @@ Example:
|
|
|
}
|
|
|
}
|
|
|
--------------------------------------------------
|
|
|
+// CONSOLE
|
|
|
+// TEST[continued]
|
|
|
|
|
|
-The above example uses `geo_centroid` as a sub-aggregation to a <<search-aggregations-bucket-terms-aggregation, terms>> bucket aggregation
|
|
|
-for finding the central location for all crimes of type burglary in each town.
|
|
|
+The above example uses `geo_centroid` as a sub-aggregation to a
|
|
|
+<<search-aggregations-bucket-terms-aggregation, terms>> bucket aggregation
|
|
|
+for finding the central location for museums in each city.
|
|
|
|
|
|
The response for the above aggregation:
|
|
|
|
|
@@ -77,28 +102,44 @@ The response for the above aggregation:
|
|
|
--------------------------------------------------
|
|
|
{
|
|
|
...
|
|
|
-
|
|
|
- "buckets": [
|
|
|
- {
|
|
|
- "key": "Los Altos",
|
|
|
- "doc_count": 113,
|
|
|
- "centroid": {
|
|
|
- "location": {
|
|
|
- "lat": 37.3924582824111,
|
|
|
- "lon": -122.12104808539152
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- "key": "Mountain View",
|
|
|
- "doc_count": 92,
|
|
|
- "centroid": {
|
|
|
- "location": {
|
|
|
- "lat": 37.382152481004596,
|
|
|
- "lon": -122.08116559311748
|
|
|
- }
|
|
|
- }
|
|
|
+ "aggregations": {
|
|
|
+ "cities": {
|
|
|
+ "sum_other_doc_count": 0,
|
|
|
+ "doc_count_error_upper_bound": 0,
|
|
|
+ "buckets": [
|
|
|
+ {
|
|
|
+ "key": "Amsterdam",
|
|
|
+ "doc_count": 3,
|
|
|
+ "centroid": {
|
|
|
+ "location": {
|
|
|
+ "lat": 52.371655656024814,
|
|
|
+ "lon": 4.909563269466162
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": "Paris",
|
|
|
+ "doc_count": 2,
|
|
|
+ "centroid": {
|
|
|
+ "location": {
|
|
|
+ "lat": 48.86055544484407,
|
|
|
+ "lon": 2.331694420427084
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": "Antwerp",
|
|
|
+ "doc_count": 1,
|
|
|
+ "centroid": {
|
|
|
+ "location": {
|
|
|
+ "lat": 51.222899928689,
|
|
|
+ "lon": 4.405199903994799
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
- ]
|
|
|
+ }
|
|
|
}
|
|
|
---------------------------------------------------
|
|
|
+--------------------------------------------------
|
|
|
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
|