首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch坐标交点

Elasticsearch坐标交点
EN

Stack Overflow用户
提问于 2021-02-15 10:26:26
回答 1查看 791关注 0票数 1

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

代码语言:javascript
复制
{
  "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]",我尝试了以下查询

代码语言:javascript
复制
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"
          }
        }
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-15 11:29:20

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

  1. 设置索引映射

代码语言:javascript
复制
PUT geoindex
{
  "mappings": {
    "properties": {
      "area": {
        "type": "float"
      },
      "center": {
        "type": "geo_point"
      },
      "geo_json": {
        "type": "geo_shape"
      },
      "name": {
        "type": "text"
      }
    }
  }
}

  1. 添加巴塞罗那多边形

代码语言:javascript
复制
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. 检查交(查询多边形为黄色):

代码语言:javascript
复制
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]]]
        }
      }
    }
  }
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66206311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档