# Reverse geo distance search

**URL:** <https://discuss.elastic.co/t/reverse-geo-distance-search/263524>\
**Category:** Elasticsearch\
**Created:** [February 7, 2021, 3:02pm UTC](https://discuss.elastic.co/t/reverse-geo-distance-search/263524 "2021-02-07T15:02:32Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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 8, 2021, 11:45pm UTC](https://discuss.elastic.co/t/reverse-geo-distance-search/263524/8 "2021-02-08T23:45:03Z")

</div>

Exactly which version of 7.X are you one that covers 10 releases which is a lot of elasticsearch releases.

Please look closely are the docs [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#_circle) and [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.10/geo-shape.html#geoshape-indexing-approach)

_" Elasticsearch supports a `circle` type, which consists of a center point with a radius. Note that this circle representation can only be indexed when using the `recursive` Prefix Tree strategy. For the default [Indexing approach](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#geoshape-indexing-approach) circles should be approximated using a `POLYGON` ."_

So your mapping is not correct and assuming that you mean London you have the lat and lon reversed in the circles definition, and I assume you mean more than 1mi.

_For all types, both the inner `type` and `coordinates` fields are required._

_In GeoJSON and WKT, and therefore Elasticsearch, the correct **coordinate order is longitude, latitude (X, Y)** within coordinate arrays. This differs from many Geospatial APIs (e.g., Google Maps) that generally use the colloquial latitude, longitude (Y, X)._

You will notice a deprecation notice I will see if I can find out more on this... but the below all works for me.

```
DELETE my-shapes
PUT my-shapes
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape",
        "tree": "quadtree"
      }
    }
  }
}

GET my-shapes/_search

PUT my-shapes/_doc/london
{
  "locationName": "london",
  "location": {
    "type": "circle",
    "coordinates": [
      -0.1277583,
      51.5073509
    ],
    "radius": "10000m"
  }
}

DELETE my-index-000001
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "text": "location 1",
  "location": { 
    "lat": 41.12,
    "lon": -71.34
  }
}

PUT my-index-000001/_doc/2
{
  "text": "location 2",
  "location": { 
    "lat": 45.12,
    "lon": -71.34
  }
}

PUT my-index-000001/_doc/3
{
  "text": "House in london",
  "location": { 
    "lat": 51.5,
    "lon": -0.127
  }
}

GET my-index-000001/_search

GET /my-index-000001/_search
{
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "location": {
            "indexed_shape": {
              "index": "my-shapes",
              "id": "london",
              "path": "location"
            },
            "relation": "intersects"
          }
        }
      }
    }
  }
}

```

results

```
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : [
      {
        "_index" : "my-index-000001",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.0,
        "_source" : {
          "text" : "House in london",
          "location" : {
            "lat" : 51.5,
            "lon" : -0.127
          }
        }
      }
    ]
  }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/reverse-geo-distance-search/263524)._
