<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Geo Distance Aggregation(地理距離聚合) 原文鏈接 : [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html) 譯文鏈接 : [Geo Distance Aggregation(地理距離聚合)](http://apache.wiki/pages/viewpage.action?pageId=10028788&src=contextnavpagetreemode) 貢獻者 : @于永超,[ApacheCN](/display/~apachecn),[Apache中文網](/display/~apachechina) ## Geo Distance Aggregation 在geo_point字段上工作的多bucket聚合和概念上的工作非常類似于[range](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html)(范圍)聚合.用戶可以定義原點的點和距離范圍的集合。聚合計算每個文檔值與原點的距離,并根據范圍確定其所屬的bucket(桶)(如果文檔和原點之間的距離落在bucket(桶)的距離范圍內,則文檔屬于bucket(桶) ) ``` 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" : { "geo_distance" : { "field" : "location", "origin" : "52.3760, 4.894", "ranges" : [ { "to" : 100000 }, { "from" : 100000, "to" : 300000 }, { "from" : 300000 } ] } } } } ``` 響應結果: ``` { ... "aggregations": { "rings_around_amsterdam" : { "buckets": [ { "key": "*-100000.0", "from": 0.0, "to": 100000.0, "doc_count": 3 }, { "key": "100000.0-300000.0", "from": 100000.0, "to": 300000.0, "doc_count": 1 }, { "key": "300000.0-*", "from": 300000.0, "doc_count": 2 } ] } } } ``` 指定的字段必須是geo_point類型(只能在映射中顯式設置)。它還可以保存一個geo_point字段的數組,在這種情況下,在聚合期間將考慮所有這些字段。原點可以接受[geo_point](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html)類型支持的所有格式: * 對象格式:{ "lat" : 52.3760, "lon" : 4.894 }-?這是最安全的格式,因為它是最明確的lat (緯度)& lon(經度)值 * 字符串格式:"52.3760, 4.894" ?-?第一個數值是lat(緯度),第二個是lon(經度) * 數組格式:[4.894, 52.3760] ?-?它基于GeoJson標準,第一個數字是lon(經度),第二個數字是lat(緯度) 在默認情況下,距離單位是m(米),但它也可以接受:mi(英里),in(英寸),yd(碼),km(公里),cm(厘米),毫米(毫米)。 ``` POST /museums/_search?size=0 { "aggs" : { "rings" : { "geo_distance" : { "field" : "location", "origin" : "52.3760, 4.894", "unit" : "km", #1 "ranges" : [ { "to" : 100 }, { "from" : 100, "to" : 300 }, { "from" : 300 } ] } } } } ``` #1 ??距離將以公里計算 有兩種距離計算模式:arc(默認) 和?plane, arc(電弧)計算模式是最準確的,plane模式是最快的,但是最不準確。當考慮搜索上下文是“narrow”,跨越較小的地理區域(約5km)可以用plane,plane將為非常大的區域(例如跨大陸搜索)的搜索返回更高的誤差區間。距離計算類型可以使用distance_type參數設置。 ``` POST /museums/_search?size=0 { "aggs" : { "rings" : { "geo_distance" : { "field" : "location", "origin" : "52.3760, 4.894", "unit" : "km", "distance_type" : "plane", "ranges" : [ { "to" : 100 }, { "from" : 100, "to" : 300 }, { "from" : 300 } ] } } } } ``` ### Keyed Response 將keyed標志設置為true會將一個惟一的字符串鍵與每個bucket(桶)關聯起來,并將范圍作為散列而不是數組返回: ``` POST /museums/_search?size=0 { "aggs" : { "rings_around_amsterdam" : { "geo_distance" : { "field" : "location", "origin" : "52.3760, 4.894", "ranges" : [ { "to" : 100000 }, { "from" : 100000, "to" : 300000 }, { "from" : 300000 } ], "keyed": true } } } } ``` 返回結果: ``` { ... "aggregations": { "rings_around_amsterdam" : { "buckets": { "*-100000.0": { "from": 0.0, "to": 100000.0, "doc_count": 3 }, "100000.0-300000.0": { "from": 100000.0, "to": 300000.0, "doc_count": 1 }, "300000.0-*": { "from": 300000.0, "doc_count": 2 } } } } } ``` 也可以為每個范圍自定義key ``` POST /museums/_search?size=0 { "aggs" : { "rings_around_amsterdam" : { "geo_distance" : { "field" : "location", "origin" : "52.3760, 4.894", "ranges" : [ { "to" : 100000, "key": "first_ring" }, { "from" : 100000, "to" : 300000, "key": "second_ring" }, { "from" : 300000, "key": "third_ring" } ], "keyed": true } } } } ``` 返回結果: ``` { ... "aggregations": { "rings_around_amsterdam" : { "buckets": { "first_ring": { "from": 0.0, "to": 100000.0, "doc_count": 3 }, "second_ring": { "from": 100000.0, "to": 300000.0, "doc_count": 1 }, "third_ring": { "from": 300000.0, "doc_count": 2 } } } } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看