Browse Source

CONSOLEify geo aggregation docs

Turns the top example in each of the geo aggregation docs into a working
example that can be opened in CONSOLE. Subsequent examples can all also
be opened in console and will work after you've run the first example.
All examples are tested as part of the build.
Nik Everett 8 years ago
parent
commit
5f91241f57

+ 0 - 5
docs/build.gradle

@@ -24,8 +24,6 @@ apply plugin: 'elasticsearch.docs-test'
  * only remove entries from this list. When it is empty we'll remove it
  * entirely and have a party! There will be cake and everything.... */
 buildRestTests.expectedUnconvertedCandidates = [
-  'reference/aggregations/bucket/geodistance-aggregation.asciidoc',
-  'reference/aggregations/bucket/geohashgrid-aggregation.asciidoc',
   'reference/aggregations/bucket/iprange-aggregation.asciidoc',
   'reference/aggregations/bucket/missing-aggregation.asciidoc',
   'reference/aggregations/bucket/nested-aggregation.asciidoc',
@@ -36,8 +34,6 @@ buildRestTests.expectedUnconvertedCandidates = [
   'reference/aggregations/matrix/stats-aggregation.asciidoc',
   'reference/aggregations/metrics/cardinality-aggregation.asciidoc',
   'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
-  'reference/aggregations/metrics/geobounds-aggregation.asciidoc',
-  'reference/aggregations/metrics/geocentroid-aggregation.asciidoc',
   'reference/aggregations/metrics/percentile-aggregation.asciidoc',
   'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',
   'reference/aggregations/metrics/scripted-metric-aggregation.asciidoc',
@@ -103,7 +99,6 @@ buildRestTests.expectedUnconvertedCandidates = [
   'reference/mapping/fields/all-field.asciidoc',
   'reference/mapping/params/analyzer.asciidoc',
   'reference/mapping/types/binary.asciidoc',
-  'reference/mapping/types/geo-point.asciidoc',
   'reference/mapping/types/geo-shape.asciidoc',
   'reference/mapping/types/ip.asciidoc',
   'reference/mapping/types/nested.asciidoc',

+ 54 - 16
docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc

@@ -5,6 +5,34 @@ A multi-bucket aggregation that works on `geo_point` fields and conceptually wor
 
 [source,js]
 --------------------------------------------------
+PUT /museums
+{
+    "mappings": {
+        "doc": {
+            "properties": {
+                "location": {
+                    "type": "geo_point"
+                }
+            }
+        }
+    }
+}
+
+POST /museums/doc/_bulk?refresh
+{"index":{"_id":1}}
+{"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
+{"index":{"_id":2}}
+{"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
+{"index":{"_id":3}}
+{"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
+{"index":{"_id":4}}
+{"location": "51.222900,4.405200", "name": "Letterenhuis"}
+{"index":{"_id":5}}
+{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
+{"index":{"_id":6}}
+{"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
+
+POST /museums/_search?size=0
 {
     "aggs" : {
         "rings_around_amsterdam" : {
@@ -12,46 +40,49 @@ A multi-bucket aggregation that works on `geo_point` fields and conceptually wor
                 "field" : "location",
                 "origin" : "52.3760, 4.894",
                 "ranges" : [
-                    { "to" : 100 },
-                    { "from" : 100, "to" : 300 },
-                    { "from" : 300 }
+                    { "to" : 100000 },
+                    { "from" : 100000, "to" : 300000 },
+                    { "from" : 300000 }
                 ]
             }
         }
     }
 }
 --------------------------------------------------
+// CONSOLE
 
 Response:
 
 [source,js]
 --------------------------------------------------
 {
+    ...
     "aggregations": {
-        "rings" : {
+        "rings_around_amsterdam" : {
             "buckets": [
                 {
-                    "key": "*-100.0",
-                    "from": 0,
-                    "to": 100.0,
+                    "key": "*-100000.0",
+                    "from": 0.0,
+                    "to": 100000.0,
                     "doc_count": 3
                 },
                 {
-                    "key": "100.0-300.0",
-                    "from": 100.0,
-                    "to": 300.0,
+                    "key": "100000.0-300000.0",
+                    "from": 100000.0,
+                    "to": 300000.0,
                     "doc_count": 1
                 },
                 {
-                    "key": "300.0-*",
-                    "from": 300.0,
-                    "doc_count": 7
+                    "key": "300000.0-*",
+                    "from": 300000.0,
+                    "doc_count": 2
                 }
             ]
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
 
 The specified field must be of type `geo_point` (which can only be set explicitly in the mappings). And it can also hold an array of `geo_point` fields, in which case all will be taken into account during aggregation. The origin point can accept all formats supported by the <<geo-point,`geo_point` type>>:
 
@@ -59,17 +90,18 @@ The specified field must be of type `geo_point` (which can only be set explicitl
 * String format: `"52.3760, 4.894"` - where the first number is the `lat` and the second is the `lon`
 * Array format: `[4.894, 52.3760]` - which is based on the `GeoJson` standard and where the first number is the `lon` and the second one is the `lat`
 
-By default, the distance unit is `m` (metres) but it can also accept: `mi` (miles), `in` (inches), `yd` (yards), `km` (kilometers), `cm` (centimeters), `mm` (millimeters).
+By default, the distance unit is `m` (meters) but it can also accept: `mi` (miles), `in` (inches), `yd` (yards), `km` (kilometers), `cm` (centimeters), `mm` (millimeters).
 
 [source,js]
 --------------------------------------------------
+POST /museums/_search?size=0
 {
     "aggs" : {
         "rings" : {
             "geo_distance" : {
                 "field" : "location",
                 "origin" : "52.3760, 4.894",
-                "unit" : "mi", <1>
+                "unit" : "km", <1>
                 "ranges" : [
                     { "to" : 100 },
                     { "from" : 100, "to" : 300 },
@@ -80,19 +112,23 @@ By default, the distance unit is `m` (metres) but it can also accept: `mi` (mile
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[continued]
 
-<1> The distances will be computed as miles
+<1> The distances will be computed in kilometers
 
 There are two distance calculation modes: `arc` (the default), and `plane`. The `arc` calculation is the most accurate. The `plane` is the fastest but least accurate. Consider using `plane` when your search context is "narrow", and spans smaller geographical areas (~5km). `plane` will return higher error margins for searches across very large areas (e.g. cross continent search). The distance calculation type can be set using the `distance_type` parameter:
 
 [source,js]
 --------------------------------------------------
+POST /museums/_search?size=0
 {
     "aggs" : {
         "rings" : {
             "geo_distance" : {
                 "field" : "location",
                 "origin" : "52.3760, 4.894",
+                "unit" : "km",
                 "distance_type" : "plane",
                 "ranges" : [
                     { "to" : 100 },
@@ -104,3 +140,5 @@ There are two distance calculation modes: `arc` (the default), and `plane`. The
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[continued]

+ 50 - 14
docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc

@@ -19,9 +19,37 @@ The specified field must be of type `geo_point` (which can only be set explicitl
 
 [source,js]
 --------------------------------------------------
+PUT /museums
+{
+    "mappings": {
+        "doc": {
+            "properties": {
+                "location": {
+                    "type": "geo_point"
+                }
+            }
+        }
+    }
+}
+
+POST /museums/doc/_bulk?refresh
+{"index":{"_id":1}}
+{"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
+{"index":{"_id":2}}
+{"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
+{"index":{"_id":3}}
+{"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
+{"index":{"_id":4}}
+{"location": "51.222900,4.405200", "name": "Letterenhuis"}
+{"index":{"_id":5}}
+{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
+{"index":{"_id":6}}
+{"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
+
+POST /museums/_search?size=0
 {
     "aggregations" : {
-        "myLarge-GrainGeoHashGrid" : {
+        "large-grid" : {
             "geohash_grid" : {
                 "field" : "location",
                 "precision" : 3
@@ -30,30 +58,35 @@ The specified field must be of type `geo_point` (which can only be set explicitl
     }
 }
 --------------------------------------------------
+// CONSOLE
 
 Response:
 
 [source,js]
 --------------------------------------------------
 {
+    ...
     "aggregations": {
-        "myLarge-GrainGeoHashGrid": {
+        "large-grid": {
             "buckets": [
                 {
-                    "key": "svz",
-                    "doc_count": 10964
+                    "key": "u17",
+                    "doc_count": 3
+                },
+                {
+                    "key": "u09",
+                    "doc_count": 2
                 },
                 {
-                    "key": "sv8",
-                    "doc_count": 3198
+                    "key": "u15",
+                    "doc_count": 1
                 }
             ]
         }
     }
 }
 --------------------------------------------------
-
-
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
 
 ==== High-precision requests
 
@@ -61,29 +94,32 @@ When requesting detailed buckets (typically for displaying a "zoomed in" map) a
 
 [source,js]
 --------------------------------------------------
+POST /museums/_search?size=0
 {
     "aggregations" : {
-        "zoomedInView" : {
+        "zoomed-in" : {
             "filter" : {
                 "geo_bounding_box" : {
                     "location" : {
-                        "top_left" : "51.73, 0.9",
-                        "bottom_right" : "51.55, 1.1"
+                        "top_left" : "52.4, 4.9",
+                        "bottom_right" : "52.3, 5.0"
                     }
                 }
             },
             "aggregations":{
                 "zoom1":{
                     "geohash_grid" : {
-                        "field":"location",
-                        "precision":8
+                        "field": "location",
+                        "precision": 8
                     }
                 }
             }
         }
     }
- }
+}
 --------------------------------------------------
+// CONSOLE
+// TEST[continued]
 
 ==== Cell dimensions at the equator
 The table below shows the metric dimensions for cells covered by various string lengths of geohash.

+ 35 - 6
docs/reference/aggregations/metrics/geobounds-aggregation.asciidoc

@@ -8,9 +8,37 @@ 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", "name": "NEMO Science Museum"}
+{"index":{"_id":2}}
+{"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
+{"index":{"_id":3}}
+{"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
+{"index":{"_id":4}}
+{"location": "51.222900,4.405200", "name": "Letterenhuis"}
+{"index":{"_id":5}}
+{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
+{"index":{"_id":6}}
+{"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
+
+POST /museums/_search?size=0
 {
     "query" : {
-        "match" : { "business_type" : "shop" }
+        "match" : { "name" : "musée" }
     },
     "aggs" : {
         "viewport" : {
@@ -22,6 +50,7 @@ Example:
     }
 }
 --------------------------------------------------
+// CONSOLE
 
 <1> The `geo_bounds` aggregation specifies the field to use to obtain the bounds
 <2> `wrap_longitude` is an optional parameter which specifies whether the bounding box should be allowed to overlap the international date line. The default value is `true`
@@ -34,20 +63,20 @@ The response for the above aggregation:
 --------------------------------------------------
 {
     ...
-
     "aggregations": {
         "viewport": {
             "bounds": {
                 "top_left": {
-                    "lat": 80.45,
-                    "lon": -160.22
+                    "lat": 48.86111099738628,
+                    "lon": 2.3269999679178
                 },
                 "bottom_right": {
-                    "lat": 40.65,
-                    "lon": 42.57
+                    "lat": 48.85999997612089,
+                    "lon": 2.3363889567553997
                 }
             }
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]

+ 79 - 38
docs/reference/aggregations/metrics/geocentroid-aggregation.asciidoc

@@ -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,/]

+ 7 - 10
docs/reference/mapping/types/geo-point.asciidoc

@@ -111,20 +111,17 @@ When accessing the value of a geo-point in a script, the value is returned as
 a `GeoPoint` object, which allows access to the `.lat` and `.lon` values
 respectively:
 
-
-[source,js]
+[source,painless]
 --------------------------------------------------
-geopoint = doc['location'].value;
-lat      = geopoint.lat;
-lon      = geopoint.lon;
+def geopoint = doc['location'].value;
+def lat      = geopoint.lat;
+def lon      = geopoint.lon;
 --------------------------------------------------
 
 For performance reasons, it is better to access the lat/lon values directly:
 
-[source,js]
+[source,painless]
 --------------------------------------------------
-lat      = doc['location'].lat;
-lon      = doc['location'].lon;
+def lat      = doc['location'].lat;
+def lon      = doc['location'].lon;
 --------------------------------------------------
-
-