GeoShape / Polygon document matching with GeoPoint query in ElasticSearch

I would like to match any document in the ES index where the dot is inside the polygon type geo_shape.

So, I would like to request a point (ie [2.934211, 42.522377]) and get correspondence with all documents where the polygon intersects with this point.

Here is my simple ES mapping:

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

And here is the 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 do a search in my index and am with a geo_shape filter like this:

{
  "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 am missing? I tried with the β€œinside” in relation with no success.

Thanks DJP

+4
source share
3 answers

Your point is not inside your polygon!

Google maps

+5
source

. :

(type = doc):

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

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

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

Source: https://habr.com/ru/post/1598175/


All Articles