# Geo shape query radius problem

**URL:** <https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323>\
**Category:** Elasticsearch\
**Created:** [February 24, 2021, 10:48am UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323 "2021-02-24T10:48:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fatih\_Kurnaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fatih_kurnaz/32/83540_2.png) [@Fatih\_Kurnaz](https://discuss.elastic.co/u/Fatih_Kurnaz)\
**Post date:** [February 24, 2021, 10:48am UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323/1 "2021-02-24T10:48:24Z")

</div>

Hi everyone;

Here my mapping;  
\</\>

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

```

\</\>

Here example document  
\</\>

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

```

\</\>

And here my search query

\</\>

```auto
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)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/1/c168f8efcc5c18573d1f516d7682716920f0ca9f.png)

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).

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/b/7b7fa0128c6e13eb76de561bf0ed0e9fa928cfed.png)

Should the query I gave above find data?

---

<div class="post-metadata">

**Author:** ![Fatih\_Kurnaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fatih_kurnaz/32/83540_2.png) [@Fatih\_Kurnaz](https://discuss.elastic.co/u/Fatih_Kurnaz)\
**Post date:** [February 25, 2021, 2:12pm UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323/2 "2021-02-25T14:12:33Z")

</div>

Is there anyone who can help me ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 25, 2021, 2:24pm UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323/3 "2021-02-25T14:24:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 25, 2021, 3:36pm UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323/4 "2021-02-25T15:36:33Z")

</div>

@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"
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 25, 2021, 3:37pm UTC](https://discuss.elastic.co/t/geo-shape-query-radius-problem/265323/5 "2021-03-25T15:37:15Z")

</div>

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