7

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

DJP
  • 73
  • 1
  • 4

3 Answers3

8

Your point is not inside your polygon !

Google Maps

Emile VAUGE
  • 121
  • 2
  • 1
    @Emilie how to easily point my polygon and query point on google map for view purpose like you did here https://www.google.com/maps/d/edit?mid=zFb8DZ_OQJ4s.kj3qtt_HQV5A&usp=sharing – A l w a y s S u n n y Aug 03 '20 at 14:37
0

The query is not working. I corrected them:

Query for mapping (type = doc):

{
"mappings": {
    "doc": {
        "properties": {
            "geometry": {
                "type": "geo_shape","tree":"quadtree","precision":"1m"
            }
        }
    }
}
}
funky-nd
  • 637
  • 1
  • 9
  • 25
0

query for search

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

    }
  },
  "filter": {
    "geo_shape": {
      "geometry": {
        "shape": {
          "coordinates": [
            2.934211,
            42.522377
          ],
          "type": "point"
        },
        "relation": "disjoint"
      }
    }
  }
}
}
 }
funky-nd
  • 637
  • 1
  • 9
  • 25