geo_shape

  1. 定義映射(需指定坐標(biāo)系)
PUT /regions
{
  "mappings": {
    "properties": {
      "name": { "type": "keyword" },
      "area": {
        "type": "geo_shape",
        "tree": "quadtree",     // 索引樹類型(默認(rèn))
        "precision": "100m"     // 精度控制(越高越精確,存儲越大)
      }
    }
  }
}
  1. 插入地理形狀數(shù)據(jù)
    2.1 多邊形(Polygon)
POST /regions/_doc/1
{
  "name": "北京五環(huán)區(qū)域",
  "area": {
    "type": "polygon",
    "coordinates": [
      [
        [116.20, 39.70],  // 多邊形頂點(diǎn)坐標(biāo)(需閉合)
        [116.50, 39.70],
        [116.50, 40.00],
        [116.20, 40.00],
        [116.20, 39.70]
      ]
    ]
  }
}

2.2 圓形(Circle)

POST /regions/_doc/2
{
  "name": "上海中心5km范圍",
  "area": {
    "type": "circle",
    "radius": "5km",          // 半徑
    "coordinates": [121.4998, 31.2397]  // 圓心
  }
}
  1. 地理形狀查詢
    3.1 查詢與某形狀相交的文檔
GET /regions/_search
{
  "query": {
    "geo_shape": {
      "area": {
        "shape": {
          "type": "point",     // 查詢點(diǎn)是否在區(qū)域內(nèi)
          "coordinates": [116.3975, 39.9087]  // 天安門坐標(biāo)
        },
        "relation": "intersects"  // 關(guān)系類型:相交
      }
    }
  }
}
// 結(jié)果:返回包含該點(diǎn)的區(qū)域(如北京五環(huán)區(qū)域)

3.2 使用預(yù)定義形狀(引用索引中的形狀)

POST /regions/_search
{
  "query": {
    "geo_shape": {
      "area": {
        "indexed_shape": {
          "index": "regions",  // 形狀來源索引
          "id": "1",           // 文檔ID
          "path": "area"       // 字段路徑
        },
        "relation": "within"   // 關(guān)系類型:完全包含在目標(biāo)形狀內(nèi)
      }
    }
  }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容