瀏覽代碼

Docs: add clarification about geohash use in geohashgrid agg (#36901)

Adds an example on translating geohashes returned by geohashgrid 
agg as bucket keys into geo bounding box filters in elasticsearch as well
as 3rd party applications.

Closes #36413
Igor Motov 6 年之前
父節點
當前提交
d6acd8e15f
共有 1 個文件被更改,包括 76 次插入0 次删除
  1. 76 0
      docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc

+ 76 - 0
docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc

@@ -121,6 +121,82 @@ POST /museums/_search?size=0
 // CONSOLE
 // TEST[continued]
 
+The geohashes returned by the `geohash_grid` aggregation can be also used for zooming in. To zoom into the
+first geohash `u17` returned in the previous example, it should be specified as both `top_left` and `bottom_right` corner:
+
+[source,js]
+--------------------------------------------------
+POST /museums/_search?size=0
+{
+    "aggregations" : {
+        "zoomed-in" : {
+            "filter" : {
+                "geo_bounding_box" : {
+                    "location" : {
+                        "top_left" : "u17",
+                        "bottom_right" : "u17"
+                    }
+                }
+            },
+            "aggregations":{
+                "zoom1":{
+                    "geohash_grid" : {
+                        "field": "location",
+                        "precision": 8
+                    }
+                }
+            }
+        }
+    }
+}
+--------------------------------------------------
+// CONSOLE
+// TEST[continued]
+
+[source,js]
+--------------------------------------------------
+{
+    ...
+    "aggregations" : {
+        "zoomed-in" : {
+            "doc_count" : 3,
+            "zoom1" : {
+                "buckets" : [
+                    {
+                        "key" : "u173zy3j",
+                        "doc_count" : 1
+                    },
+                    {
+                        "key" : "u173zvfz",
+                        "doc_count" : 1
+                    },
+                    {
+                        "key" : "u173zt90",
+                        "doc_count" : 1
+                    }
+                ]
+            }
+        }
+    }
+}
+--------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
+
+For "zooming in" on the system that don't support geohashes, the bucket keys should be translated into bounding boxes using
+one of available geohash libraries. For example, for javascript the https://github.com/sunng87/node-geohash[node-geohash] library
+can be used:
+
+[source,js]
+--------------------------------------------------
+var geohash = require('ngeohash');
+
+// bbox will contain [ 52.03125, 4.21875, 53.4375, 5.625 ]
+//                   [   minlat,  minlon,  maxlat, maxlon]
+var bbox = geohash.decode_bbox('u17');
+--------------------------------------------------
+// NOTCONSOLE
+
+
 ==== Cell dimensions at the equator
 The table below shows the metric dimensions for cells covered by various string lengths of geohash.
 Cell dimensions vary with latitude and so the table is for the worst-case scenario at the equator.