elasticsearch Geop Shape query not working

38 Views Asked by At

One of my document (id = emergency) is a circle having a 30000 meter radius:

    GET seller-67/_doc/emergency
    {
      "_index": "seller-67",
      "_type": "_doc",
      "_id": "emergency",
      "_version": 1,
      "_seq_no": 0,
      "_primary_term": 1,
      "found": true,
      "_source": {
        "location": {
          "type": "circle",
          "coordinates": [
            99.8131968,
            13.550437
          ],
          "radius": "30000m"
        }
      }
    }

I want to figure if the point

lat = 13.7054285, lon = 99.5806321

is inside this circle.

To do so I'm using the following request:

    POST seller-67/_search
    {
      "query": {
        "bool": {
          "filter": [
            {
              "geo_shape": {
                "location": {
                  "shape": {
                    "type": "point",
                    "coordinates": [
                      99.5806321,
                      13.7054285
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }

the answer is the following:

    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "seller-67",
            "_type" : "_doc",
            "_id" : "emergency",
            "_score" : 1.0,
            "_source" : {
              "location" : {
                "coordinates" : [
                  99.8131968,
                  13.550437
                ],
                "type" : "circle",
                "radius" : "30000m"
              }
            }
          }
        ]
      }
    }

So according to the answer, the point lat = 13.7054285, lon = 99.5806321 is inside the document emergency (circle 30000m radius, center: lat = 13.550437, lon = 99.8131968) But when I'm computing the distance between those 2 points, the result is 3045m. enter image description here

Since 3045 > 3000, how come elasticsearch returns this result to my request?

1

There are 1 best solutions below

0
Paulo On

Tldr;

Hi, circle are not a native shape in latest release of elasticsearch. They use polygons to approximate a circle.

Could you be using this under the hood ? This could explain the error ? as it is embedded in the pipeline.