Geo shape query radius problem

Hi everyone;

Here my mapping;
</>

PUT /circle-example
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape",
        "strategy": "recursive"
      }
    }
  }
}

</>

Here example document
</>

POST /circle-example/_doc
{
  "location" : {
    "type" : "circle",
    "coordinates" : [70.0, 1.0],
    "radius" : "25mi"
  }
}

</>

And here my search query

</>

GET circle-example/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                  70.0, 0.0
                ],
                "relation": "contains"
              }
            }
          }
        }
      ]
    }
  }
}

</>

And result of this search is this . (No data)

Which means; Elasticsearch says that [70.0, 0.0] is not in circle whose center is [70.0, 1.0] and radius is 25 miles.

However when I calculate between [70.0, 0.0] and [70.0, 1.0], I found 23,63 miles (smaller than radius).

Should the query I gave above find data?

Is there anyone who can help me ?

If I recall correctly coordinates are longitude, latitude in Elasticsearch rather than latitude, longitude. Would this explain the difference? Can you try swapping them?

@Fatih_Kurnaz

Try This... but it feels a bit backwards you are going to get the shape back every search.
Note: I think you can use intersects or contains ... I think intersects might be faster / more efficient but am not completely sure. you can test

PUT _ingest/pipeline/polygonize_circles
{
  "description": "translate circle to polygon",
  "processors": [
    {
      "circle": {
        "field": "location",
        "error_distance": 100, <-- That means 100m error possibility 
        "shape_type": "geo_shape"
      }
    }
  ]
}

GET my-circle
DELETE my-circle
PUT my-circle
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape"
      }
    }
  }
}


POST my-circle/_doc/?pipeline=polygonize_circles
{
  "locationName": "nowhere",
  "location": {
    "type": "circle",
    "coordinates": [
      1,
      70
    ],
    "radius": "25mi"
  }
}


POST my-circle/_doc/?pipeline=polygonize_circles
{
  "locationName": "london",
  "location": {
    "type": "circle",
    "coordinates": [
      1,
      51
    ],
    "radius": "25mi"
  }
}

GET my-circle/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                 0, 70.0
                ],
                "relation": "contains"
              }
            }
          }
      }
    }
  }
}

If you don't actually want the shape to come back

GET my-circle/_search
{
  "size" : 0, <--- 
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                 0, 70.0
                ],
                "relation": "contains"
              }
            }
          }
      }
    }
  }
}

The results will look like this.

{
  "took" : 12,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1, <--- Means it will be found but you wont know which one
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

if want just the name of the matching circle

GET my-circle/_search
{
  "_source": "locationName",  <---- This will return the location name
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "point",
                "coordinates": [
                 0, 70.0
                ],
                "relation": "contains"
              }
            }
          }
      }
    }
  }
}

result

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-circle",
        "_type" : "_doc",
        "_id" : "Ys7N2XcB-yLzgGFD36Ru",
        "_score" : 1.0,
        "_source" : {
          "locationName" : "nowhere"
        }
      }
    ]
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.