【问题标题】:Elasticsearch get intersection of coordinatesElasticsearch获取坐标的交点
【发布时间】:2021-02-15 19:29:34
【问题描述】:

我有一个索引field,使用它,给定一组多边形坐标,我想获得与这些坐标相交的任何字段。考虑到使用elasticsearch 地理位置功能的field 索引的结构,这是否可能?我正在使用弹性搜索 7.9 版

{
  "geo_json": {
    "geometry": {
      "coordinates": [
        [
          [
            2.1228971832029644,
            41.3011586218355
          ],
          [
            2.122596585111679,
            41.3012384865674
          ],
          [
            2.1221786804481835,
            41.30191870980272
          ],
          [
            2.1223509744761158,
            41.302042636348716
          ],
          [
            2.1226735685285507,
            41.30192972550523
          ],
          [
            2.1232820963718857,
            41.30165984025794
          ],
          [
            2.1232820963718857,
            41.30131559725024
          ],
          [
            2.1228971832029644,
            41.3011586218355
          ]
        ]
      ],
      "type": "Polygon"
    },
    "properties": null,
    "type": "Feature"
  },
  "name": "Barcelona"
}

我尝试了以下查询,返回错误"Field [geo_json.geometry.coordinates] is of unsupported type [float]. [geo_shape] query supports the following types [geo_shape,geo_point]"

GET field/_search
{
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "geo_json.geometry.coordinates": {
            "shape": {
              "type": "polygon",
              "coordinates": [
                [
                  [
                    2.1228971832029644,
                    41.3011586218355
                  ],
                  [
                    2.122596585111679,
                    41.3012384865674
                  ],
                  [
                    2.1221786804481835,
                    41.30191870980272
                  ],
                  [
                    2.1223509744761158,
                    41.302042636348716
                  ],
                  [
                    2.1226735685285507,
                    41.30192972550523
                  ],
                  [
                    2.1232820963718857,
                    41.30165984025794
                  ],
                  [
                    2.1232820963718857,
                    41.30131559725024
                  ],
                  [
                    2.1228971832029644,
                    41.3011586218355
                  ]
                ]
              ]
            },
            "relation": "intersects"
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch intersection


    【解决方案1】:

    这当然是可能的。使 my previous answer 适应您的用例:

    1. 设置索引映射
    PUT geoindex
    {
      "mappings": {
        "properties": {
          "area": {
            "type": "float"
          },
          "center": {
            "type": "geo_point"
          },
          "geo_json": {
            "type": "geo_shape"
          },
          "name": {
            "type": "text"
          }
        }
      }
    }
    
    1. 添加巴塞罗那多边形
    POST geoindex/_doc
    {
      "area": 5380.8444064004625,
      "center": [ 2.1227303884100346, 41.30160062909211 ],
      "geo_json": {
        "type": "polygon",
        "coordinates": [[[2.1228971832029644,41.3011586218355],[2.122596585111679,41.3012384865674],[2.1221786804481835,41.30191870980272],[2.1223509744761158,41.302042636348716],[2.1226735685285507,41.30192972550523],[2.1232820963718857,41.30165984025794],[2.1232820963718857,41.30131559725024],[2.1228971832029644,41.3011586218355]]]
      },
      "name": "Barcelona"
    }
    
    1. 检查交叉点(查询多边形为黄色):
    POST geoindex/_search
    {
      "query": {
        "geo_shape": {
          "geo_json": { 
            "relation": "intersects",
            "shape": {
              "type":  "polygon",
              "coordinates": [[[2.122421264648437,41.30061251600798],[2.123579978942871,41.300354591849114],[2.123579978942871,41.30120896171846],[2.122957706451416,41.30129762210163],[2.122421264648437,41.30061251600798]]]
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 2014-04-21
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多