elasticsearch 导入基础数据并索引之 geo_shape

我们看到的图形, 实际是由点来完成的, 

有2种类型的格子模型可用于地理星座, 默认使用的是geoHash, 还有一种4叉树(quad trees), 也可用于

判断形状与索引的形状关系

  1), intersects: 查询的形状与索引形状有重叠(默认)

  2), disjoint: 查询的形状与索引的ixngzhuang完全不重叠

  3), within: 索引的形状被包含在查询中

建立mapping时, 需要明确映射: 

PUT /attractions
{
  "mappings": {
    "landmark": {
      "properties": {
        "name": {
          "type": "string"
        },
        "location": {
          "type": "geo_shape"
        }
      }
    }
  }
}

数据存储: 

每个形状包含2个信息: 形状类型: point, line, polygon, envelop, 或者 一个或多经纬度点集合的数组

比如: 

PUT /attractions/landmark/dam_square
{
    "name" : "Dam Square, Amsterdam",
    "location" : {
        "type" : "polygon", <1>
        "coordinates" : [[ <2>
          [ 4.89218, 52.37356 ],
          [ 4.89205, 52.37276 ],
          [ 4.89301, 52.37274 ],
          [ 4.89392, 52.37250 ],
          [ 4.89431, 52.37287 ],
          [ 4.89331, 52.37346 ],
          [ 4.89305, 52.37326 ],
          [ 4.89218, 52.37356 ]
        ]] // lon, lat
    }
}
  • <1> type参数指明如何使用经纬度坐标集来表示对应形状。
  • <2> 用来表示多边形的经纬度坐标点列表。

查询形状: 

GET /attractions/landmark/_search
{
  "query": {
    "geo_shape": {
      "location": { // 使用的字段
        "shape": {  // shape见对应的内容表示
          "type":   "circle", // 为1km的圆
          "radius": "1km"
          "coordinates": [  // 中心点
            4.89994,
            52.37815
          ]
        }
      }
    }
  }
}

  以上摘自: https://es.xiaoleilu.com/340_Geoshapes/78_Indexed_geo_shapes.html, 未亲自测试

接下来是java API的方法

 

posted @ 2017-03-09 16:07  bronk  阅读(1742)  评论(0编辑  收藏  举报