0

I am facing am issue, I know how to find all geo_points in a particular radius but I need to find how many regions or geo_shape a particular point lies in. To solve this issue, I have made following index:

PUT /users

And this mapping:

PUT /users/_mapping/_doc
{
    "properties": {
        "radius": {
          "type": "geo_shape",
          "tree": "quadtree",
          "precision": "100m"
        },
        "point":{
          "type":"geo_point"
        }
      }

}

Also following is the sample document:

POST /users/_doc
{
    "radius":{
      "type" : "circle",
      "coordinates" : [28.363157, 77.287550],
      "radius" : "100km"
    },
    "point":{
      "lat" : 28.363157,
      "lon": 77.287550
    }

}

The query I am making is:

POST /users/_search
{
    "query":{
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_shape": {
                    "radius": {
                        "shape": {
                            "type": "point",
                            "coordinates" : [29.363157, 77.28755]
                        },
                        "relation": "contains"
                    }
                }
            }
        }
    }
}

Now, the distance between the latlongs in query and doc is almost 110-112kms, hence above query returns exact result, but when I query [30.363157, 77.28755], it still returns the document even when the distance is over 220kms.

What am I doing wrong?

sphinx
  • 717
  • 1
  • 7
  • 19
  • I've mapped the circle and the second point (30.363157, 77.28755) and the latter falls well within the circle. You can see it here: https://gist.github.com/consulthys/5ec4c720faa69462cbee5f3e16dfd418 – Val Oct 31 '18 at 11:01
  • I think your map is wrong, 30.363157, 77.28755 lies some where in India! Is it possible for you to tell me how are you making this map? – sphinx Oct 31 '18 at 11:08
  • see https://drive.google.com/open?id=1EqLsYKiscQHRSTt243w8iQStvswHSFLW&usp=sharing – sphinx Oct 31 '18 at 11:18
  • I guess I have found my stupidity, coordinates are in [lon, lat] format, I was expecting them as [lat, lon]. – sphinx Oct 31 '18 at 11:32
  • The map is correct, believe me. [GeoJSON mandates lon, lat](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html) ;-) But indeed, if you reverse lon<->lat then your point is outside of the circle around New Dehli. – Val Oct 31 '18 at 11:42
  • yeah I believe you!!!! answer the question, I will mark accepted :D – sphinx Oct 31 '18 at 11:56

0 Answers0