Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match a GeoShape/Polygon document with a GeoPoint query in ElasticSearch

I would like to match any document in the ES index where a point is within the document polygon geo_shape type.

So basicly, I'd like to query for a point (ie. [2.934211, 42.522377]), and get a match with all the documents where the polygon intersects with that point.

Here's my simple ES mapping :

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

And here an indexed document :

{
"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
        ]
    ]
]
}

When I search in my index and type with a geo_shape filter like that :

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

I have no results :

{

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

}

Any idea on what I'm missing ? I tried with "within" in relation without any success too.

Thanks, DJP

like image 543
DJP Avatar asked Jul 16 '15 08:07

DJP


1 Answers

Your point is not inside your polygon !

Google Maps

like image 58
Emile VAUGE Avatar answered Sep 28 '22 05:09

Emile VAUGE