日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Elasticsearches通過坐標位置實現對附近人的搜索_其它綜合

作者:Jeff的技術棧 ? 更新時間: 2022-06-18 編程語言

一 創建mapping

PUT test
{
  "mappings": {
    "test":{
      "properties": {
        "location":{
          "type": "geo_point"
        }
      }
    }
  }
}

二 導入數據

POST test/test
{
  "location":{
    "lat":12,
    "lon":24
  }
}

三 查詢

3.1根據給定兩個點組成的矩形,查詢矩形內的點

GET test/test/_search
{
  "query": {
    "geo_bounding_box": {
      "location": {
        "top_left": {
          "lat": 28,
          "lon": 10
        },
        "bottom_right": {
          "lat": 10,
          "lon": 30
        }
      }
    }
  }
}

3.2根據給定的多個點組成的多邊形,查詢范圍內的點

GET test/test/_search
{
  "query": {
    "geo_polygon": {
      "location": {
        "points": [
          {
            "lat": 11,
            "lon": 25
          },
          {
            "lat": 13,
            "lon": 25
          },
          {
            "lat": 13,
            "lon": 23
          },
          {
            "lat": 11,
            "lon": 23
          }
        ]
      }
    }
  }
}

3.3查詢給定1000KM距離范圍內的點

GET test/test/_search
{
  "query": {
    "geo_distance": {
      "distance": "1000km",
      "location": {
        "lat": 12,
        "lon": 23
      }
    }
  }
}

3.4查詢距離范圍區間內的點的數量

GET test/test/_search
{
  "size": 0, 
  "aggs": {
    "myaggs": {
      "geo_distance": {
        "field": "location",
        "origin": {
          "lat": 52.376,
          "lon": 4.894
        },
        "unit": "km", 
        "ranges": [
          {
            "from": 50, 
            "to": 30000
          }
        ]
      }
    }
  }
}

原文鏈接:https://www.cnblogs.com/guyouyin123/p/13308748.html

欄目分類
最近更新