将GeoShape / Polygon文档与ElasticSearch中的GeoPoint查询进行匹配

时间:2015-07-16 08:11:39

标签: elasticsearch geocoding geojson

我想匹配ES索引中文档多边形geo_shape类型中的任何文档。

基本上,我想查询一个点(即[2.934211,42.522377]),并获得与多边形与该点相交的所有文档的匹配。

这是我的简单ES映射:

{"geometry":{"type":"geo_shape","tree":"quadtree","precision":"1m"}}

这是一个索引文件:

{
"geometry": {
"type": "polygon",
"coordinates": [
    [
        [
            2.9109533049198
            ,
            42.525105483878
        ]
        ,
        [
            2.9110769445829
            ,
            42.531703894436
        ]
        ,
        [
            2.9032846986744
            ,
            42.539733810015
        ]
        ,
        [
            2.9030996511561
            ,
            42.556013979376
        ]
        ,
        [
            2.9131331966995
            ,
            42.562962734203
        ]
        ,
        [
            2.9135244444206
            ,
            42.569759384018
        ]
        ,
        [
            2.917877044124
            ,
            42.57088655519
        ]
        ,
        [
            2.9319395143989
            ,
            42.568900684816
        ]
        ,
        [
            2.9403405122874
            ,
            42.572016209123
        ]
        ,
        [
            2.9363870185385
            ,
            42.561333977005
        ]
        ,
        [
            2.9309712722105
            ,
            42.534037916636
        ]
        ,
        [
            2.9109533049198
            ,
            42.525105483878
        ]
    ]
]
}

当我在索引中搜索并使用类似的geo_shape过滤器输入时:

{
  "query": {
    "match_all": {}
  },
  "filter": {
    "geo_shape": {
      "geometry": {
    "relation": "intersects",
    "shape": {
      "coordinates": [
        2.934211,
        42.522377
      ],
      "type": "point"
    }
      }
    }
  }
}

我没有结果:

{

    "took": 3,
    "timed_out": false,
    "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
    },
    "hits": {
    "total": 0,
    "max_score": null,
    "hits": [ ]
    }

}

对我失踪的事情有任何想法?我在“内部”中尝试过没有任何成功。

谢谢, DJP

3 个答案:

答案 0 :(得分:5)

你的观点不在你的多边形内部!

Google Maps

答案 1 :(得分:0)

查询无效。我纠正了他们:

查询映射(type = doc):

{
"mappings": {
    "doc": {
        "properties": {
            "geometry": {
                "type": "geo_shape","tree":"quadtree","precision":"1m"
            }
        }
    }
}
}

答案 2 :(得分:0)

查询搜索

{
"query": {
"bool": {
  "must": {
    "match_all": {

    }
  },
  "filter": {
    "geo_shape": {
      "geometry": {
        "shape": {
          "coordinates": [
            2.934211,
            42.522377
          ],
          "type": "point"
        },
        "relation": "disjoint"
      }
    }
  }
}
}
 }